Memory leak monitoring method, device, electronic device and storage medium
By recording memory allocation and release information, generating memory call relationships and operation function information, the problem of difficult location of memory leaks is solved, and fast and accurate memory leak location and maintenance are achieved.
Patent Information
- Application Number
- CN202210841335.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-18
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2042-07-18
AI Technical Summary
Existing technologies are unable to intuitively and accurately locate the specific location that causes memory leaks, resulting in inaccurate memory leak test results and inability to effectively guide memory optimization.
By recording memory allocation and release information, determining the target memory address, generating an address file based on the memory call relationship, using the hook function to intercept memory operations, tracking the memory call relationship, generating memory operation function information, and locating the starting call address of the memory leak.
Quickly and accurately locate memory leaks, improve memory problem solving efficiency, and provide clear memory maintenance guidance.
Smart Images

Figure CN115145791B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of memory management technology, and in particular to a memory leak monitoring method, device, electronic device, and storage medium. Background Art
[0002] During application operation, due to some known or unknown reasons, the dynamically allocated memory in the application may not be released, resulting in the occupation and waste of memory space, which in turn slows down the application's operation speed and may even cause the application to crash.
[0003] Regarding the problem of memory leaks, on the one hand, existing memory leak testing solutions can usually only determine whether there is a leak in the overall memory, but cannot directly locate the specific location that causes the memory leak; on the other hand, since it tests the entire memory, the test results of such testing solutions are not accurate and may result in misjudgment. Even if a memory leak occurs, it may not be tested. Such general and inaccurate memory leak test results cannot serve as a good guide for optimizing applications. Summary of the Invention
[0004] The present disclosure provides a memory leak monitoring method, device, electronic device, and storage medium to at least solve the problem in related technologies that it is difficult to intuitively and accurately locate the specific location that causes the memory leak. The technical solution of the present disclosure is as follows:
[0005] According to a first aspect of an embodiment of the present disclosure, a memory leak monitoring method is provided, the memory leak monitoring method comprising: determining a target memory address where a memory leak exists during the running process of a monitored application; determining a memory call relationship associated with the target memory address based on call information between memory addresses saved during the running process of the application; based on the memory call relationship, determining memory operation function information corresponding to the memory address of the starting call in the memory call relationship, wherein the memory address of the starting call is the starting call address that causes the memory leak of the target memory address, and the memory operation function information is used to determine the memory operation function corresponding to the memory address of the starting call.
[0006] Optionally, the step of determining a target memory address where a memory leak exists during the running process of the monitored application includes: recording memory allocation information and memory release information during the running process of the application, wherein the memory allocation information indicates an allocated memory address, and the memory release information indicates a released memory address; by comparing the memory allocation information and the memory release information, determining target memory allocation information for which corresponding memory release information does not exist in the memory allocation information, so as to determine the target memory address where the memory leak exists from the target memory allocation information.
[0007] Optionally, during the running of the application, the step of recording memory allocation information of allocating memory and memory release information of releasing memory includes: during the running of the application, recording the memory allocation information by setting a hook function when calling the memory allocation function for allocating memory, and recording the memory release information by setting a hook function when calling the memory release function for releasing memory.
[0008] Optionally, the memory leak monitoring method also includes: generating an address file based on the memory call relationship, wherein the address file includes call sequence information between memory addresses in the memory call relationship, system library information corresponding to each memory address, and the memory size occupied by the target memory address.
[0009] Optionally, based on the memory call relationship, the step of determining the memory operation function information corresponding to the memory address of the starting call in the memory call relationship includes: determining the memory operation function information corresponding to all memory addresses in the memory call relationship based on the correspondence between the memory address and the memory operation function information saved during the running of the application; generating a parsing file containing the memory operation function information corresponding to all memory addresses; and determining the memory operation function information corresponding to the memory address of the starting call in the memory call relationship based on the parsing file.
[0010] Optionally, before executing the step of determining a target memory address where a memory leak exists during the running process of the monitored application, the memory leak monitoring method further includes: selecting a portion of the multiple dependent libraries of the monitored application to monitor for memory leaks.
[0011] According to a second aspect of an embodiment of the present disclosure, a memory leak monitoring device is provided, comprising: a first determination unit configured to determine a target memory address where a memory leak exists during the running of a monitored application; a second determination unit configured to determine a memory call relationship associated with the target memory address based on call information between memory addresses saved during the running of the application; and a third determination unit configured to determine, based on the memory call relationship, memory operation function information corresponding to the memory address of the starting call in the memory call relationship, wherein the memory address of the starting call is the starting call address that causes the memory leak of the target memory address, and the memory operation function information is used to determine the memory operation function corresponding to the memory address of the starting call.
[0012] Optionally, the first determination unit is further configured to: record memory allocation information and memory release information during the running of the application, wherein the memory allocation information indicates the allocated memory address and the memory release information indicates the released memory address; determine the target memory allocation information for which corresponding memory release information does not exist in the memory allocation information by comparing the memory allocation information and the memory release information, so as to determine the target memory address where the memory leak exists from the target memory allocation information.
[0013] Optionally, the first determination unit is further configured to: during the running of the application, record the memory allocation information by setting a hook function when calling the memory allocation function for allocating memory, and record the memory release information by setting a hook function when calling the memory release function for releasing memory.
[0014] Optionally, the memory leak monitoring device also includes a generation unit, which is configured to generate an address file based on the memory call relationship, wherein the address file includes call sequence information between memory addresses in the memory call relationship, system library information corresponding to each memory address, and the memory size occupied by the target memory address.
[0015] Optionally, the third determination unit is further configured to: determine the memory operation function information corresponding to all memory addresses in the memory call relationship based on the correspondence between the memory address and the memory operation function information saved during the running of the application; generate a parsing file containing the memory operation function information corresponding to all memory addresses; and determine the memory operation function information corresponding to the memory address of the starting call in the memory call relationship based on the parsing file.
[0016] Optionally, the memory leak monitoring device further includes a selection unit, and the selection unit is configured to select a part of the multiple dependent libraries of the monitored application to monitor the memory leak.
[0017] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor, wherein the processor executable instructions, when executed by the processor, prompt the processor to execute the memory leak monitoring method according to the present disclosure.
[0018] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of a server, the server is enabled to execute the memory leak monitoring method according to the present disclosure.
[0019] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, which includes computer instructions, and when the computer instructions are executed by a processor, the memory leak monitoring method according to the present disclosure is implemented.
[0020] The technical solutions provided by the embodiments of the present disclosure bring at least the following beneficial effects:
[0021] By determining the memory operation function information corresponding to the memory address of the starting call in the memory call relationship, the problem of not being able to intuitively and accurately locate the specific location that causes the memory leak can be solved, thereby allowing the memory leak location to be captured quickly and effectively, providing guidance for memory maintenance, and improving the efficiency of solving memory problems.
[0022] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute an improper limitation of the present disclosure.
[0024] Figure 1 The figure is a flowchart of a method for monitoring memory leaks according to an exemplary embodiment.
[0025] Figure 2 The present invention is a flowchart showing a step of determining a target memory address in a method for monitoring a memory leak according to an exemplary embodiment.
[0026] Figure 3 The present invention is a flowchart showing the steps of determining memory operation function information in a memory leak monitoring method according to an exemplary embodiment.
[0027] Figure 4 The figure is a flowchart showing an application example of a method for monitoring memory leaks according to an exemplary embodiment.
[0028] Figure 5 The figure is a block diagram showing a device for monitoring memory leaks according to an exemplary embodiment.
[0029] Figure 6 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0030] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0031] It should be noted that the terms "first," "second," and the like in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the numbers used in this manner are interchangeable where appropriate so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure as detailed in the appended claims.
[0032] It should be noted that the phrase "at least one of the items" in this disclosure includes three types of parallel situations: "any one of the items", "a combination of any multiple items of the items", and "all of the items". For example, "including at least one of A and B" includes the following three parallel situations: (1) including A; (2) including B; (3) including A and B. For another example, "performing at least one of step 1 and step 2" includes the following three parallel situations: (1) performing step 1; (2) performing step 2; and (3) performing steps 1 and 2.
[0033] It should also be noted that the exemplary embodiments of the present disclosure can be applied to electronic devices loaded with applications, including but not limited to personal computers, portable computers, tablet computers, smartphones, wearable smart devices, etc. In addition, although the following description uses the application scenario of an application running under the Android operating system as an example, it should be understood that the application scenarios of the memory leak monitoring method and apparatus according to the exemplary embodiments of the present disclosure are not limited to this, and can also be applied to any other application scenario involving any operating system involving memory leak monitoring.
[0034] In addition, it should be noted that the memory leak monitoring method according to the exemplary embodiment of the present disclosure can be applied to monitor whether memory leaks occur in the Native layer during the operation of the application. The Native layer of the application can refer to a program module or component written in C++ or C. The Native layer involves the allocation and release of memory, but it is not easy to obtain information about its memory operations. Therefore, it is not easy to effectively monitor memory leaks in the Native layer. Therefore, the memory leak monitoring method according to the exemplary embodiment of the present disclosure can effectively monitor the Native layer of the application. However, the present disclosure is not limited to this, and it can also be applied to other memory leak monitoring scenarios.
[0035] In view of the above problems, a memory leak monitoring method, a memory leak monitoring device, an electronic device, a computer-readable storage medium, and a computer program product according to exemplary embodiments of the present disclosure will be provided below with reference to the accompanying drawings.
[0036] Figure 1 FIG. 1 is a flow chart showing a method for monitoring memory leaks according to an exemplary embodiment. Figure 1 As shown, the memory leak monitoring method includes the following steps:
[0037] In step S10, a target memory address where a memory leak occurs during the running process of the monitored application may be determined.
[0038] During application execution, a certain amount of memory space needs to be dynamically allocated to execute functions, and the allocated memory space needs to be released after execution. During this process, if the allocated memory space is not successfully released, it cannot be allocated again, resulting in a decrease in the total available memory capacity, which can cause the application to run slower, or even freeze or crash. Therefore, when detecting memory leaks, it is necessary to determine the target memory address where the memory leak occurs.
[0039] As an example, Figure 2 As shown, in step S10, the target memory address where the memory leak occurs can be determined in the following manner:
[0040] In step S11, memory allocation information and memory release information may be recorded during the running of the application, wherein the memory allocation information indicates an allocated memory address, and the memory release information indicates a released memory address.
[0041] As an example, during the running of an application, memory allocation information and memory release information can be recorded by setting a hook function. Specifically, during the running of an application, when a memory allocation function for allocating memory is called, a hook function can be set to record memory allocation information, and when a memory release function for releasing memory is called, a hook function can be set to record memory release information.
[0042] Here, the memory allocation function may include, for example, the malloc function, the realloc function, the calloc function, the valloc function, the memalign function, and the new function, and the memory release function may include, for example, the free function and the delete function. However, the present disclosure is not limited to this, and the memory allocation function and the memory release function may also be in other forms.
[0043] In order to avoid wasting memory space, the memory allocation function and the memory release function need to be called one-to-one. If only the memory allocation function is called without the memory release function, the allocated memory cannot be released. As the amount of unreleased memory increases, the application may run slower or crash. In this regard, according to an exemplary embodiment of the present disclosure, a hook function can be added to the memory allocation location each time memory is allocated, and the current memory start address and the occupied memory size can be recorded through the hook function as memory allocation information; a hook function can also be added to the memory release location each time memory is released, and the current memory start address and the released memory size can be recorded through the hook function as memory release information.
[0044] Here, hook technology refers to a technology that changes the execution process of a program. During application operation, the call of a specified type of function can be intercepted by adding a hook function in the process. For example, as mentioned above, when calling a memory allocation function or a memory release function, the called memory address and memory operation information (for example, the occupied memory size or the released memory size) can be obtained by setting a hook function.
[0045] For example, the memory allocation information may record "allocated memory address: 0×123, 0×987, 0×899", and the memory release information may record "released memory address: 0×123, 0×987".
[0046] As mentioned above, by setting a hook function, for example, the memory allocation information and memory release information in the function call process can be intercepted, which makes it easier to analyze memory leaks. When a memory leak is found, the target memory address where the memory leak occurs can be directly determined. This is compared with the existing memory leak testing method, which can only know the existence of a memory leak as a whole but cannot determine the leaked memory address. This greatly improves the convenience of memory analysis and maintenance for operators.
[0047] In the above example, by setting a hook function to record memory allocation information and memory release information, memory allocation information and memory release information can be recorded quickly and efficiently, making it more convenient and quick to find information. However, it should be noted that the exemplary embodiments of the present disclosure are not limited to this, and memory allocation and release can also be recorded in other ways.
[0048] In step S12, the memory allocation information and the memory release information may be compared to determine target memory allocation information for which corresponding memory release information does not exist in the memory allocation information, so as to determine the target memory address where the memory leak exists from the target memory allocation information.
[0049] Based on the recorded memory allocation information and memory release information, in step S12, while the application is running or when the application exits or after the application exits, it can be determined by comparing the memory allocation information and the memory release information. If the memory allocation information corresponds one-to-one with the memory release information, it can be considered that there is no memory leak; if allocation information for which there is no corresponding memory release information appears in the memory allocation information, it is determined that a memory leak problem has occurred, and the memory address of the memory leak can be determined from the allocation information for which there is no corresponding memory release information, that is, the target memory address described in this step.
[0050] Taking the memory allocation information and memory release information described above as an example, by comparison, it can be seen that in the memory allocation information, "allocated memory address: 0×899" has no corresponding memory release information, that is, the memory address 0×899 has not been released, and there is a memory leak. This memory address is the target memory address found.
[0051] In addition, according to an exemplary embodiment of the present disclosure, before executing the step of determining the target memory address where a memory leak exists during the running process of the monitored application, the memory leak monitoring method may also include: selecting a portion of the multiple dependent libraries of the monitored application to monitor for memory leaks.
[0052] Specifically, the monitored application may correspond to multiple dependent libraries, and some of these dependent libraries can be selectively monitored. In this way, the memory leak problem of the application can be monitored more specifically, and the specific dependent library can be located according to the memory leak monitoring results, providing clear guidance for memory maintenance and improving the efficiency of solving memory problems.
[0053] return Figure 1 In step S20, a memory call relationship associated with the target memory address may be determined based on the call information between the memory addresses saved during the running process of the application.
[0054] During application execution, the memory address of the instruction's machine code is recorded each time the assembly code of an instruction is called. When multiple instructions are called, the call relationship between the memory addresses corresponding to the instructions is recorded in sequence. For example, this call relationship can be stored in the form of a stack. Accordingly, in this step, the memory call relationship associated with the target memory address can be determined based on the call information between the stored memory addresses through stack backtracing.
[0055] Still using the above example, once the target memory address is determined, the calling relationship of the target memory address can be obtained by backtracing the calling relationship between memory addresses through the stack. For example, in an Android system application scenario, the calling relationship of the target memory address can be reversed in Android's underlying library libutils. For example, the memory calling relationship can be found to be "0×899 / 0×233 / 0×234 / 0×234 / 0×236".
[0056] Furthermore, according to exemplary embodiments of the present disclosure, when the memory calling relationship is determined, an address file may be generated based on the memory calling relationship to be saved for use in subsequent operations.
[0057] Here, the address file may include calling sequence information between memory addresses in the memory calling relationship, system library information corresponding to each memory address, and memory size occupied by the target memory address.
[0058] For example, the address file may be in the form of the following Table 1:
[0059] Table 1
[0060] libMemAnaStub.so,libtest.so 0×899 64 1:0×233 1|0×234 1|0×234 1|0×236 1
[0061] In the preceding table, libMemAnaStub.so and libtest.so are system library files. They are numbered from left to right, with the first system library numbered 0 and the second system library numbered 1. The left-to-right order of memory addresses represents the calling sequence, with memory address 0x236 being the starting address. 0x899 64 1 indicates that the memory address 0x899 occupies 64 bytes and that it comes from libtest.so, the system library numbered 1. 0x233 1 indicates that the memory address 0x233 comes from the system library numbered 1. Other memory addresses are represented in a similar manner and are not detailed here.
[0062] According to the exemplary embodiment of the present disclosure, the address file contains the main information for analyzing memory leaks. In this way, subsequent analysis work can be carried out based on the address file. Even if the application is exited or the operating system of the device is restarted, the memory leak problem can still be analyzed through the address file.
[0063] In step S30, based on the memory call relationship, the memory operation function information corresponding to the memory address of the starting call in the memory call relationship can be determined, wherein the memory address of the starting call is the starting call address that causes the memory leak of the target memory address, and the memory operation function information is used to determine the memory operation function corresponding to the memory address of the starting call.
[0064] In this step, the memory address of the initial call to the target memory address can be obtained from the memory call relationship, for example, by querying the address file described above. The memory address of the initial call is the location that causes the memory leak, but the representation of the memory address is usually only a coding of the memory. The operator cannot directly determine which memory operation function in the code causes the memory leak through the coding, which is inconvenient to maintain the code. In this case, according to an exemplary embodiment of the present disclosure, the memory operation function that causes the memory leak can be determined based on the memory operation function information corresponding to the memory address of the initial call. Here, the memory operation function can be a function that allocates or releases memory.
[0065] Specifically, if Figure 3 As shown, the memory operation function information can be determined in the following ways:
[0066] In step S31, the memory operation function information corresponding to all memory addresses in the memory call relationship may be determined based on the correspondence between the memory addresses and the memory operation function information stored during the running process of the application.
[0067] Here, during the execution of the application, the correspondence between the memory address and the memory operation function information can be saved. The memory operation function information can be used to locate the called function corresponding to the memory address. For example, the memory operation function information can include the executable file corresponding to the memory operation function and the location of the memory operation function within the executable file. As an example, the correspondence between the memory address and the memory operation function information can be compiled into an image file having a symbol table. The symbol table can be used to save the correspondence between the memory address and the memory operation function information. Each time a memory operation function is called, the information of the called memory operation function and the corresponding memory address can be updated in the symbol table.
[0068] For example, in the application scenario of the Android system, taking the memory call relationship shown in Table 1 above as an example, it is known that there are 64 bytes at the memory address "0×899" that have not been released, and its call relationship is "0×899 / 0×233 / 0×234 / 0×234 / 0×236", which exists in the libtest.so file. Based on Android's own addr2line tool, the stack information of the above call relationship can be queried from the correspondence between the memory address and the memory operation function information as follows:
[0069] Memory address / file name:line number
[0070] 0×899 / test.cc:8
[0071] 0×233 / test.cc:29
[0072] 0×234 / test.cc:137
[0073] 0×234 / test.cc:246
[0074] 0×236 / main.cc:18
[0075] Based on the above stack information, it can be determined that the starting location of memory allocation is line 18 of the "main.cc" file, and its calling relationship is line 18 of main.cc → line 246 of test.cc → line 137 of test.cc → line 29 of test.cc → line 8 of test.cc.
[0076] In step S32, a parsing file containing memory operation function information corresponding to all memory addresses is generated.
[0077] In step S33, based on the parsed file, the memory operation function information corresponding to the memory address of the initial call in the memory call relationship is determined.
[0078] In steps S32 and S33, the memory operation function information corresponding to all memory addresses can be saved in a file, so that the file can be queried to determine the memory leak situation. Here, the parsed file can include the target memory address, the system library information corresponding to the target memory address, the memory size occupied by the target memory address, and the memory operation function information.
[0079] For example, the parsed file can be in a file format that can be displayed in a predetermined manner, such as an HTML file format. Thus, an operator can directly locate the function location where the memory leak occurs by opening the parsed file. Compared to analyzing memory address information in memory call relationships, this can quickly and effectively capture the memory leak location and display complete memory operation function information, thereby improving problem solving efficiency.
[0080] As described above, the memory leak monitoring method according to the exemplary embodiment of the present disclosure can solve the problem of being unable to intuitively and accurately locate the specific location that causes the memory leak by determining the memory operation function information corresponding to the memory address of the starting call in the memory call relationship, thereby allowing the memory leak location to be captured quickly and effectively, providing guidance for memory maintenance, and improving the efficiency of solving memory problems.
[0081] Figure 4 The figure is a flowchart showing an application example of a method for monitoring memory leaks according to an exemplary embodiment.
[0082] like Figure 4 As shown, in step S1, the above-mentioned memory leak monitoring method can be encapsulated into a memory analysis (MemoryAnalyze) tool, and during the encapsulation process, the dependent library file to be monitored is set. The memory analysis tool can be adapted to a specified operating system, for example, it can be encapsulated for an Android system. Here, the dependent library can refer to a dynamic link library in an application, and one or more of the dynamic link libraries can be selected for monitoring. The memory analysis tool can, for example, be generated as an installation package in apk format for installation on an electronic device. During the installation process, for example, the target dynamic link library can be modified, such as setting a target git repository, and compiling to generate a system library file with a symbol table, such as a mirror file in so format, where the symbol table is used to save the mapping relationship between memory addresses and corresponding memory operation function information.
[0083] In step S2, after the application is run, an address file is generated for the electronic device equipped with the memory analysis tool. Specifically, after the application completes the corresponding operation, the kill-12pid command for generating the address file can be called in the adb shell command, thereby generating an address file in the system's sdcard directory, for example, named hook.txt.
[0084] In step S3, a python parsing command may be executed in the adb shell command to generate a parsing file based on the address file. For example, a python HookParser.py--html-ihook.log-s. / symbols / >mem.html file may be generated. Based on the parsing file, the stack details of the currently unreleased memory may be displayed in detail.
[0085] Based on the memory allocation stack details displayed in the parsed file, you can quickly locate the location where memory has been allocated but not released, thereby resolving memory leaks.
[0086] In the above application example, a memory analysis tool can be encapsulated based on the memory leak monitoring method according to the exemplary embodiment of the present disclosure, so that it can be quickly accessed into the existing operating system to perform memory leak monitoring on the applications that need to be monitored, thereby realizing automated monitoring operations and directly providing the located memory leak location without the need to manually organize and analyze scattered system information to determine the memory leak location.
[0087] Figure 5 FIG. 1 is a block diagram of a memory leak monitoring device according to an exemplary embodiment. Figure 5 The device 10 includes a first determining unit 100 , a second determining unit 200 and a third determining unit 300 .
[0088] The first determining unit 100 may be configured to determine a target memory address where a memory leak occurs during the execution of the monitored application.
[0089] The second determining unit 200 may be configured to determine a memory calling relationship associated with the target memory address based on calling information between memory addresses saved during the running process of the application.
[0090] The third determining unit 300 may be configured to determine, based on the memory call relationship, the memory operation function information corresponding to the memory address of the initial call in the memory call relationship. Here, the memory address of the initial call is the initial call address that causes the memory leak of the target memory address, and the memory operation function information is used to determine the memory operation function corresponding to the memory address of the initial call.
[0091] As an example, the first determination unit 100 can also be configured to: record memory allocation information and memory release information during the running process of the application, wherein the memory allocation information indicates the allocated memory address and the memory release information indicates the released memory address; by comparing the memory allocation information and the memory release information, determine the target memory allocation information for which the corresponding memory release information does not exist in the memory allocation information, so as to determine the target memory address where the memory leak exists from the target memory allocation information.
[0092] As an example, the first determination unit 100 can also be configured to: during the running process of the application, record memory allocation information by setting a hook function when calling a memory allocation function for allocating memory, and record memory release information by setting a hook function when calling a memory release function for releasing memory.
[0093] As an example, the memory leak monitoring device may further include a generating unit 400, which may be configured to generate an address file based on the memory call relationship. Here, the address file may include call sequence information between memory addresses in the memory call relationship, system library information corresponding to each memory address, and the memory size occupied by the target memory address.
[0094] As an example, the third determination unit 300 can also be configured to: determine the memory operation function information corresponding to all memory addresses in the memory call relationship based on the correspondence between the memory address and the memory operation function information saved during the running process of the application; generate a parsing file containing the memory operation function information corresponding to all memory addresses; based on the parsing file, determine the memory operation function information corresponding to the memory address of the starting call in the memory call relationship.
[0095] As an example, the memory leak monitoring device further includes a selection unit, which is configured to select a portion of the dependent libraries of the monitored application from among the multiple dependent libraries to monitor for memory leaks.
[0096] Regarding the apparatus in the above embodiment, the specific manner in which each unit performs operations has been described in detail in the embodiment of the method, and will not be elaborated on here.
[0097] Figure 6 FIG. 1 is a block diagram of an electronic device according to an exemplary embodiment. Figure 6 As shown, the electronic device 1000 includes a processor 101 and a memory 102 for storing processor-executable instructions. Here, when the processor-executable instructions are executed by the processor, the processor is prompted to execute the memory leak monitoring method as described in the above exemplary embodiment.
[0098] As an example, the electronic device 1000 does not necessarily have to be a single device, but can also be any collection of devices or circuits that can execute the above instructions (or instruction sets) individually or in combination. The electronic device 1000 can also be part of an integrated control system or system manager, or can be configured as a server that is interconnected with a local or remote (e.g., via wireless transmission) interface.
[0099] In electronic device 1000, processor 101 may include a central processing unit (CPU), a graphics processing unit (GPU), a programmable logic device, a dedicated processor system, a microcontroller, or a microprocessor. By way of example and not limitation, processor 101 may also include an analog processor, a digital processor, a microprocessor, a multi-core processor, a processor array, a network processor, etc.
[0100] The processor 101 may execute instructions or codes stored in the memory 102, which may also store data. Instructions and data may also be sent and received over a network via a network interface device, which may employ any known transmission protocol.
[0101] Memory 102 may be integrated with processor 101, for example, by placing RAM or flash memory within an integrated circuit microprocessor or the like. Furthermore, memory 102 may comprise a separate device, such as an external disk drive, a storage array, or any other storage device usable by a database system. Memory 102 and processor 101 may be operatively coupled or may communicate with each other, for example, via an I / O port, a network connection, or the like, such that processor 101 can access files stored in memory 102.
[0102] In addition, the electronic device 1000 may further include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, a mouse, a touch input device, etc.) All components of the electronic device 1000 may be connected to each other via a bus and / or a network.
[0103] In an exemplary embodiment, a computer-readable storage medium may also be provided, which, when the instructions in the computer-readable storage medium are executed by the processor of the server, enables the server to execute the memory leak monitoring method as described in the above exemplary embodiment. The computer-readable storage medium may be, for example, a memory including instructions. Optionally, the computer-readable storage medium may be: read-only memory (ROM), random access memory (RAM), random access programmable read-only memory (PROM), electrically erasable programmable read-only memory (EEPROM), dynamic random access memory (DRAM), static random access memory (SRAM), flash memory, non-volatile memory, CD-ROM, CD-R, CD+R, CD-RW, CD+RW, DVD-ROM, DVD-R, DVD+R, DVD-RW, DVD+RW, DVD-RAM, BD-ROM, BD-R, BD-R LTH, BD-RE, Blu-ray or optical disk storage, hard disk drive (HDD), solid state drive (SSD), card storage (such as, multimedia card, secure digital (SD) card or ultra-fast digital (XD) card), magnetic tape, floppy disk, magneto-optical data storage device, optical data storage device, hard disk, solid state disk and any other device, any other device configured to store the computer program and any associated data, data files and data structures in a non-transitory manner and provide the computer program and any associated data, data files and data structures to a processor or computer so that the processor or computer can execute the computer program. The computer program in the above-mentioned computer-readable storage medium can be run in an environment deployed in a computer device such as a client, a host, an agent device, a server, etc. In addition, in one example, the computer program and any associated data, data files and data structures are distributed on a networked computer system so that the computer program and any associated data, data files and data structures are stored, accessed and executed in a distributed manner by one or more processors or computers.
[0104] In an exemplary embodiment, a computer program product may also be provided. The computer program product includes computer instructions. When the computer instructions are executed by a processor, the memory leak monitoring method as described in the above exemplary embodiment is implemented.
[0105] Other embodiments of the present disclosure will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the present disclosure being indicated by the following claims.
[0106] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A memory leak monitoring method, characterized in that: The memory leak monitoring method includes: Determine the target memory address where the memory leak occurs during the operation of the monitored application; determining a memory call relationship associated with the target memory address based on call information between memory addresses saved during the running of the application, wherein the memory call relationship represents a call relationship between memory addresses; Based on the memory call relationship, determining the memory operation function information corresponding to the memory address of the starting call in the memory call relationship, wherein the memory address of the starting call is the starting call address that causes the memory leak of the target memory address, and the memory operation function information is used to determine the memory operation function corresponding to the memory address of the starting call, The memory leak monitoring method further comprises: generating an address file based on the memory call relationship, wherein the address file includes call sequence information between memory addresses in the memory call relationship, system library information corresponding to each memory address, and the memory size occupied by the target memory address. The step of determining the memory operation function information corresponding to the memory address of the initial call in the memory call relationship based on the memory call relationship includes: Determining the memory operation function information corresponding to all memory addresses in the memory call relationship based on the correspondence between the memory addresses and the memory operation function information stored during the running of the application; Based on the address file, generating a parsing file containing memory operation function information corresponding to all memory addresses, wherein the parsing file is in a file format that can be displayed in a predetermined display manner; Based on the parsed file, memory operation function information corresponding to the memory address of the starting call in the memory call relationship is determined.
2. The memory leak monitoring method according to claim 1, characterized in that: The steps of determining a target memory address where a memory leak occurs during the running of the monitored application include: During the running of the application, recording memory allocation information and memory release information, wherein the memory allocation information indicates an allocated memory address, and the memory release information indicates a released memory address; By comparing the memory allocation information with the memory release information, target memory allocation information for which corresponding memory release information does not exist in the memory allocation information is determined, so as to determine a target memory address where a memory leak exists from the target memory allocation information.
3. The memory leak monitoring method according to claim 2, characterized in that: During the running of the application, the step of recording memory allocation information of allocating memory and memory release information of releasing memory includes: During the running of the application, the memory allocation information is recorded by setting a hook function when a memory allocation function for allocating memory is called, and the memory release information is recorded by setting a hook function when a memory release function for releasing memory is called.
4. The memory leak monitoring method according to claim 1, wherein: Before executing the step of determining a target memory address where a memory leak exists during the running process of the monitored application, the memory leak monitoring method further includes: selecting a portion of the multiple dependent libraries of the monitored application to monitor for memory leaks.
5. A memory leak monitoring device, characterized in that: The memory leak monitoring device includes: a first determining unit configured to determine a target memory address where a memory leak occurs during the running of the monitored application; a second determining unit configured to determine a memory calling relationship associated with the target memory address based on calling information between memory addresses saved during the running of the application, wherein the memory calling relationship represents a calling relationship between memory addresses; The third determining unit is configured to determine, based on the memory call relationship, memory operation function information corresponding to the memory address of the starting call in the memory call relationship, wherein the memory address of the starting call is the starting call address that causes the memory leak of the target memory address, and the memory operation function information is used to determine the memory operation function corresponding to the memory address of the starting call, The memory leak monitoring device further includes a generating unit, which is configured to generate an address file based on the memory call relationship, wherein the address file includes calling sequence information between memory addresses in the memory call relationship, system library information corresponding to each memory address, and the memory size occupied by the target memory address. The third determining unit is further configured to: Determining the memory operation function information corresponding to all memory addresses in the memory call relationship based on the correspondence between the memory addresses and the memory operation function information stored during the running of the application; Based on the address file, generating a parsing file containing memory operation function information corresponding to all memory addresses, wherein the parsing file is in a file format that can be displayed in a predetermined display manner; Based on the parsed file, memory operation function information corresponding to the memory address of the starting call in the memory call relationship is determined.
6. The memory leak monitoring device according to claim 5, characterized in that: The first determining unit is further configured to: During the running of the application, recording memory allocation information and memory release information, wherein the memory allocation information indicates an allocated memory address, and the memory release information indicates a released memory address; By comparing the memory allocation information with the memory release information, target memory allocation information for which corresponding memory release information does not exist in the memory allocation information is determined, so as to determine a target memory address where a memory leak exists from the target memory allocation information.
7. The memory leak monitoring device according to claim 6, characterized in that: The first determining unit is further configured to: During the running of the application, the memory allocation information is recorded by setting a hook function when a memory allocation function for allocating memory is called, and the memory release information is recorded by setting a hook function when a memory release function for releasing memory is called.
8. The memory leak monitoring device according to claim 5, characterized in that: The memory leak monitoring device further includes a selection unit configured to select a portion of the dependent libraries of the monitored application among the multiple dependent libraries for memory leak monitoring.
9. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing instructions executable by the processor, When the processor-executable instructions are executed by the processor, the processor is prompted to execute the memory leak monitoring method according to any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that When the instructions in the computer-readable storage medium are executed by a processor of a server, the server is enabled to execute the memory leak monitoring method according to any one of claims 1 to 4.
11. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by a processor, the memory leak monitoring method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Memory leak monitoring method and device and electronic equipment
CN110908865A
Memory leak detection method and device, readable storage medium and electronic equipment
CN111966603A