Method, device and equipment for detecting leak memory

By maintaining the allocated and cited memory sets, regularly scanning the heap space to identify leaked memory, solving the limitations of existing tools in terms of performance overhead, memory footprint and false alarm rate, and achieving efficient and accurate memory leak detection, suitable for Production environment.

CN118981422APending Publication Date: 2024-11-19XINHUASAN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410950934.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-16
Publication Date
2024-11-19

Smart Images

  • Figure CN118981422A_ABST
    Figure CN118981422A_ABST
Patent Text Reader

Abstract

The invention provides a method, a device and equipment for detecting a leak memory, which are used for solving the technical problems related to leak memory detection. According to the method, the allocated memory set which records the information of the memory space successfully allocated from the heap is maintained, the heap space of the process is periodically scanned, the memory with the reference relationship is stored in the imported memory set, and the leaked memory is identified by subtracting the imported memory set from the allocated memory set. The method does not need a third-party tool, does not need to modify a memory allocation mechanism of the process, can be used as a part of process functions, is controlled to be turned on and turned off through a switch, has no invasion to codes, and can be applied to a production environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device and equipment for detecting memory leakage. Background Art

[0002] As the complexity of software systems continues to increase, memory management and memory leaks have become one of the most challenging issues. Memory leaks refer to the situation where no longer needed memory is properly released during program execution, resulting in a waste of system memory resources and ultimately performance degradation. Especially for long-running or massively concurrent applications, memory leaks may cause system stability issues or even fatal crashes. Therefore, for programs on operating systems such as Linux, how to efficiently detect and resolve memory leaks has become a challenge that needs to be addressed.

[0003] At present, there are some tools and technologies for memory leak detection, such as Valgrind and AddressSanitizer. However, these existing technologies still have certain limitations in practical application, such as performance overhead and false alarm rate. Therefore, it is necessary to propose new methods and technologies to improve the accuracy, efficiency and applicability of memory leak detection.

[0004] Valgrind is a very powerful memory debugging tool, but it also has some shortcomings, including:

[0005] 1. Performance overhead: Valgrind has a certain impact on the performance of the program, because it needs to dynamically analyze and monitor the program, which will cause the program to run slower, sometimes even dozens of times slower.

[0006] 2. Memory usage: Valgrind itself will occupy additional memory resources. Especially when processing large programs, a large amount of memory may be required to store monitoring information, which may cause certain pressure on the overall memory resources of the system.

[0007] 3. Not suitable for real-time systems: Due to performance overhead and additional memory usage, Valgrind may cause serious interference when analyzing real-time systems, so its scope of application is limited to a certain extent.

[0008] 4. False positive rate: Sometimes Valgrind will have a certain degree of false positives, that is, marking some non-real memory leak problems, which may increase the user's analysis workload and make the analysis results inaccurate.

[0009] AddressSanitizer is also a memory management and detection tool that can detect memory leaks, but it also has some shortcomings, including:

[0010] 1. Performance overhead: When using AddressSanitizer, the program will run slower because of the need to track and detect memory accesses. This performance overhead may affect the actual performance of the program to a certain extent.

[0011] 2. Increased compilation time: AddressSanitizer needs to insert additional code at compile time to track and detect memory accesses, which may increase the compilation time of the program.

[0012] 3. Memory usage: AddressSanitizer requires additional memory during operation to store metadata and tracking information of memory accesses, which will increase the overall memory usage.

[0013] 4. Can only be enabled at compile time: AddressSanitizer needs to be enabled when compiling the program and cannot be loaded dynamically, which makes it have certain limitations for debugging and analysis of compiled programs.

[0014] Based on the above analysis, we can see that the current detection of memory leaks mainly relies on third-party tools. These third-party tools need to take over the normal memory application and release process in the code, and then use the memory allocation and management mechanism of the third-party tools. This is invasive to the code and is generally suitable for use in the joint debugging phase after system development is completed, and cannot be used in a formal production environment. Summary of the invention

[0015] In view of this, the present invention provides a method, device and equipment for detecting leaked memory, which are used to solve technical problems related to leaked memory detection.

[0016] According to an aspect of an embodiment of the present invention, the present invention provides a method for detecting memory leakage, the method comprising:

[0017] During the process running, each time a memory application is successfully made from the heap, the memory space information of the successful application is added to the allocated memory set (g_AllMallocMem); each time a piece of memory that is no longer in use is successfully released, the released memory space information is deleted from the allocated memory set;

[0018] After the process is started, the heap space of the process is scanned regularly, and the memory with reference relationship is put into the referenced memory set (g_AllUsedMem);

[0019] After scanning the heap space of the process and building the referenced memory set (g_AllUsedMem), the memory space that exists in the allocated memory set (g_AllMallocMem) but does not exist in the referenced memory set (g_AllUsedMem) is identified as leaked memory.

[0020] Furthermore, the allocated memory set adopts a linked list structure, and the linked list structure unit stores memory space information in the form of a tuple of an offset address and a memory space size, and is organized into a linked list structure in ascending order according to the starting offset address of the memory space.

[0021] Furthermore, the method of periodically scanning the heap space of the process and putting the memory with a reference relationship into the referenced memory set is:

[0022] After the process is initialized, read the memory scan timer interval configuration;

[0023] When the memory scan timer interval value is not zero, the memory leak detection function is enabled and the memory scan timer is started;

[0024] After the memory scan timer times out, it starts traversing the data segment space of the process;

[0025] Traverse the memory content in the data segment space. If the memory content contains a heap address and the heap address is in the allocated memory set, the memory space pointed to by the heap address is used as the first-level reference memory and its memory space information is stored in the referenced memory set.

[0026] Traverse the first-level reference memory. If its content contains a heap address and the heap address is in the allocated memory set, the memory space pointed to by the heap address is used as the second-level reference memory and its memory space information is stored in the referenced memory set.

[0027] The newly added hierarchical reference memory is traversed in sequence until there is no reference memory in the current hierarchical reference memory. The traversal ends and the final referenced memory set is obtained.

[0028] Furthermore, when there is a situation where the upper-level reference memory references the lower-level reference memory, and the lower-level reference memory references the upper-level reference memory, when traversing to the lower-level reference memory, its reference relationship to the upper-level reference memory is ignored.

[0029] Furthermore, the method is applied to the Linux operating system.

[0030] Based on another aspect of an embodiment of the present invention, the present application further provides a device for detecting memory leakage, the device comprising:

[0031] The allocated memory set maintenance module is used to add the successfully applied memory space information to the allocated memory set (g_AllMallocMem) each time the memory is successfully applied from the heap during the process running; each time a piece of memory that is no longer used is successfully released, the released memory space information is deleted from the allocated memory set;

[0032] The referenced memory set maintenance module is used to periodically scan the heap space of the process after the process is started, and put the memory with reference relationship into the referenced memory set (g_AllUsedMem);

[0033] The leak memory identification module is used to identify the memory space that exists in the allocated memory set (g_AllMallocMem) but not in the referenced memory set (g_AllUsedMem) as leak memory after scanning the heap space of the process and building the referenced memory set (g_AllUsedMem).

[0034] Furthermore, the allocated memory set adopts a linked list structure, and the linked list structure unit stores memory space information in the form of a tuple of an offset address and a memory space size, and is organized into a linked list structure in ascending order according to the starting offset address of the memory space.

[0035] Furthermore, the referenced memory set maintenance module includes:

[0036] The configuration reading module is used to read the memory scan timer interval configuration after the process is initialized; when the memory scan timer interval value is not zero, the memory leak detection function is enabled and the memory scan timer is started;

[0037] The timing scanning module is used to start traversing the data segment space of the process after the memory scanning timer times out;

[0038] Traverse the memory content in the data segment space. If the memory content contains a heap address and the heap address is in the allocated memory set, the memory space pointed to by the heap address is used as the first-level reference memory and its memory space information is stored in the referenced memory set.

[0039] Traverse the first-level reference memory. If its content contains a heap address and the heap address is in the allocated memory set, the memory space pointed to by the heap address is used as the second-level reference memory and its memory space information is stored in the referenced memory set.

[0040] The newly added hierarchical reference memory is traversed in sequence until there is no reference memory in the current hierarchical reference memory. The traversal ends and the final referenced memory set is obtained.

[0041] The technical solution of the present invention maintains an allocated memory set that records the memory space information successfully allocated from the heap, and by periodically scanning the heap space of the process, puts the memory with a reference relationship into the referenced memory set, and identifies the leaked memory by subtracting the referenced memory set from the allocated memory set. The present invention does not require the use of third-party tools, does not need to modify the memory allocation mechanism of the process itself, can be used as part of the process function, and can be turned on and off by a switch control, is non-invasive to the code, and can be applied to the production environment. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments of the present invention or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings of the embodiments of the present invention.

[0043] Figure 1 This is a schematic diagram of the organizational structure of process memory in a Linux-like operating system;

[0044] Figure 2 A schematic diagram of the reference relationship between the memory requested from the heap and the global variables in the data segment;

[0045] Figure 3 A schematic diagram of a method for detecting memory leaks in an embodiment of the present invention;

[0046] Figure 4 A schematic diagram of a reference relationship between memories in one embodiment of the present invention;

[0047] Figure 5 A schematic diagram of a mutual reference relationship between memories in one embodiment of the present invention;

[0048] Figure 6 A schematic diagram of the structure of an electronic device provided in one embodiment of the present invention for implementing the method for detecting memory leakage provided in the present invention. DETAILED DESCRIPTION

[0049] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, rather than limiting the embodiments of the present invention. The singular forms of "a", "said" and "the" used in the embodiments of the present invention are also intended to include plural forms, unless the context clearly indicates other meanings. Although the embodiments of the present invention may be described in a first, second, or third manner, this description is only used to distinguish similar information, entities, or steps, rather than to describe a specific order or sequence. For example, without departing from the scope of the embodiments of the present invention, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. For another example, in some scenarios, the first information may refer to one information or to multiple information of the same type. In addition, the word "if" used may be interpreted as "at..." or "when..." or "in response to determination". The "and / or" in the present invention is only a kind of association relationship describing the associated objects, indicating that there may be three relationships, for example, A and / or B, which may represent: A exists alone, A and B exist at the same time, and B exists alone, wherein A and B may be singular or plural. In addition, in the description of the present invention, unless otherwise specified, "multiple" refers to two or more than two. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can mean: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or plural.

[0050] The specific implementation process of the present invention is described in detail below in conjunction with the drawings and specific embodiments. It should be noted that the steps shown in the processes of the drawings and embodiments can be executed in a computer system such as a set of computer executable instructions, and one or more of the exemplified method steps can be single or multiple or aggregated together and run in the computer system in the form of a software module or a virtual device. Moreover, although the exemplified step process has time and sequential logic, the present invention is not limited to these steps in certain cases. They can be executed in an order different from that here. Under the guidance of the purpose of the present invention, simple changes or combinations of the execution order of these steps should also fall within the scope of the disclosure of the embodiments of the present invention.

[0051] Figure 1 This is a schematic diagram of the organizational structure of process memory in a Linux-like operating system. The embodiment of the present invention takes the Linux system process memory layout as an example for explanation, but is also applicable to other operating systems derived from Linux and other Linux-like operating systems. The memory space shown in the figure refers to the virtual memory space allocated to the process, and the memory space mainly includes:

[0052] Kernel space: Located in the high address part, it is used to store the operating system kernel and kernel-related data structures and codes. This part of memory is invisible to user programs.

[0053] User stack: Located in the high address part, it is used to store function calls and local variables, etc. The stack is a first-in-last-out (FILO) data structure, and the stack pointer changes dynamically with the call and return of the function.

[0054] Shared libraries and heaps: Located in the low address part, they are the main running space for user programs. Shared libraries are shared by multiple processes and are used to store shared library codes and data required by executable programs. The heap is an area for dynamically allocating memory, managed by functions such as malloc(), realloc(), and free(). The memory leak detection described in the present invention refers to detecting whether the application code misses releasing the allocated memory when it needs to release the memory after allocating memory from this area. If the allocated memory is missed, it may eventually cause the system to crash.

[0055] Data segment: Located in the low address part, it is used to store global variables and static variables. The data segment does not grow or shrink dynamically, but its size is determined before the program runs.

[0056] Code segment: Located in the low address part, it stores the machine instructions of the program, including executable code and read-only data.

[0057] For the application system, each piece of memory requested from the heap will eventually be attributed to a global variable through tracing, that is, it will eventually be attributed to the data segment. The so-called tracing means that each piece of memory requested from the heap is associated with its parent level, and the source of the reference is traced back based on the reference relationship.

[0058] Figure 2 This is a schematic diagram of the reference relationship between the memory requested from the heap and the global variables in the data segment. Based on the memory reference relationship, if a piece of memory on the heap is found to have no reference relationship, then this memory can be identified as leaked memory.

[0059] Figure 3 This is a flow chart of the steps of a method for detecting memory leaks in one embodiment of the present invention. The method includes:

[0060] Step 301. During the process running, each time a memory application (malloc) is successfully made from the heap, the memory space information of the successful application is added to the allocated memory set (g_AllMallocMem); each time a piece of memory that is no longer in use is successfully released (free), the released memory space information is deleted from the allocated memory set;

[0061] The present invention maintains an allocated memory set g_AllMallocMem to store all memory space information successfully requested from the heap of the process virtual memory space.

[0062] After successfully applying for memory space from the heap through the standard memory application function (malloc), the information of the applied memory space (offset address addr and space size length) is added to the g_AllMallocMem collection.

[0063] When a piece of memory that is no longer in use is successfully released through the memory release function (free), the released memory space information is deleted from the g_AllMallocMem collection.

[0064] The memory space information in the g_AllMallocMem collection includes the memory space information of the currently used memory blocks and the leaked memory blocks. Since the implementation of the standard malloc function and free function is not changed, it is non-invasive.

[0065] In one embodiment of the present invention, the g_AllMallocMem collection may adopt a linked list structure, and the linked list structure unit stores memory space information in the form of a tuple (addr, addr+length), and is organized into a linked list structure by sorting the starting offset address addr of the memory space from small to large. The search of the linked list structure may use a binary search. Assuming that g_AllMallocMem adopts this linked list structure and scans the space in units of 8 bytes, if the content in the 8-byte memory space is an address, and then see which record of the applied memory table this address is located in (addr+length), the first address of the corresponding allocated memory space is known.

[0066] Step 302: After the process is started, the heap space of the process is scanned regularly, and the memory with a reference relationship is put into the referenced memory set (g_AllUsedMem).

[0067] The method to generate the referenced memory set is:

[0068] S01. After the process is initialized, read the memory scan timer interval configuration;

[0069] S02. When the memory scan timer interval value is not zero, the memory leak detection function is turned on and the memory scan timer is started;

[0070] The present invention can use whether the memory scan timer interval configuration value is 0 as a switch for the leak memory detection function. When the value is not 0, it indicates that the leak memory detection function is turned on, and when it is 0, it indicates that the leak memory detection function is turned off.

[0071] S03. After the memory scan timer times out, start traversing the data segment space of the process (which can be traversed by reading the / proc / $pid / maps file, where "$pid" represents the process ID);

[0072] S04. Traverse the memory content in the data segment space. If the data segment memory content contains a heap address and the heap address is in the g_AllMallocMem set, the memory space pointed to by the heap address is used as the first-level reference memory and its memory space information is stored in the g_AllUsedMem set.

[0073] S05. Then traverse the first-level reference memory, if its content contains a heap address and the heap address is in the g_AllMallocMem set, the memory space pointed to by the heap address is used as the second-level reference memory and its memory space information is stored in the g_AllUsedMem set.

[0074] S06. Continue to traverse the secondary reference memory. If its content contains a heap address and the heap address is in the g_AllMallocMem set, the memory space pointed to by the heap address is used as the tertiary reference memory and its memory space information is stored in the g_AllUsedMem set.

[0075] S07. Traverse the latest added hierarchical reference memory in the above manner until there is no reference memory in the current hierarchical reference memory, and the traversal ends to obtain the final g_AllUsedMem set. For example, when traversing the third-level reference memory, if its content contains a heap address but the address is not in the g_AllMallocMem set, the traversal ends.

[0076] Figure 4 The figure is a schematic diagram of a reference relationship between memories in one embodiment of the present invention. In the example of the figure, the content of memory block A includes a heap address, namely, memory address B1, and the heap address points to a part of the memory space in the g_AllMallocMem set, namely, memory block B. For example: B1 is stored in A, but B1 is actually an offset of memory block B. At this time, address B1 is used to search the linked list in the g_AllMallocMem set to obtain the base address of the memory space where address B1 is located, namely, the address of memory block B. The address offset of memory block B is added to the g_AllUsedMem set.

[0077] Figure 5 This is a schematic diagram of a mutual reference relationship between memories in one embodiment of the present invention. In the process of executing memory scanning traversal to build the g_AllUsedMem collection, you may encounter a situation where there are mutual references between memories. If this situation is not handled, it will cause the traversal to enter an infinite loop. When encountering this situation, the following processing method can be used:

[0078] When traversing the upper-level reference memory, obtain the lower-level reference memory it references, and add the memory space information corresponding to the lower-level reference memory to the g_AllUsedMem collection. When continuing to traverse the lower-level reference memory, if it is found that the memory it references already exists in the g_AllUsedMem collection, the referenced memory space information will no longer be added to the g_AllUsedMem collection. For example, when traversing the first-level reference memory, add the second-level reference memory it references to the g_AllUsedMem collection. When continuing to traverse the second-level reference memory, it is found that the memory address it references points to the first-level reference memory that already exists in the g_AllUsedMem collection. At this time, this reference relationship is ignored.

[0079] Step 303. After scanning the heap space of the process and constructing the referenced memory set (g_AllUsedMem), the memory space that exists in the allocated memory set (g_AllMallocMem) but does not exist in the referenced memory set (g_AllUsedMem) is identified as leaked memory.

[0080] At this point, the memory leak detection process of the process is completed. The memory leak detection method provided by the present invention does not require the use of third-party tools, does not modify the memory allocation mechanism of the process itself, can be used as part of the process function, can be turned on and off by switch control, is non-invasive to the code and can be applied to the production environment.

[0081] Figure 6 A schematic diagram of the structure of an electronic device for implementing the method for detecting leaked memory provided by the present invention is provided in one embodiment of the present invention. The device 600 includes: a processor 610 such as a central processing unit (CPU), a communication bus 620, a communication interface 640, and a memory 630. The processor 610 and the memory 630 can communicate with each other through the communication bus 620. The memory 630 stores a computer program, and when the computer program is executed by the processor 310, the function of one or more steps in the method for detecting leaked memory provided by the present invention can be implemented.

[0082] Among them, memory refers to a device based on a certain storage medium for storing computer programs and / or data. It can be a volatile memory (VM, often called memory) or a non-volatile memory (NVM). Memory refers to an internal memory that directly exchanges data with the processor. It can read and write data at any time and at a very fast speed. It is used as a storage medium for temporary data of the operating system and other running programs. Memory can be synchronous dynamic random access memory (SDRAM), dynamic random access memory (DRAM), etc. Non-volatile memory refers to a memory that uses a persistent storage medium. It has the characteristics of large capacity and persistent data storage. It can be a storage class memory (SCM), a solid state disk (SSD), a NAND flash memory, a disk, etc. SCM is the industry's general term for new storage media between memory and flash memory. It is a composite storage technology that combines persistent storage characteristics and memory characteristics at the same time. The access speed is slower than DRAM and faster than SSD hard disks.

[0083] The processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0084] It should be appreciated that embodiments of the present invention may be implemented or implemented by computer hardware, a combination of hardware and software, or by computer instructions stored in a non-transitory (or non-persistent) memory. The method may be implemented in a computer program using standard programming techniques, including a non-transitory storage medium configured with a computer program, wherein the storage medium configured in this way causes the computer to operate in a specific and predefined manner. Each program may be implemented in a high-level procedural or object-oriented programming language to communicate with a computer system. However, if necessary, the program may be implemented in an assembly or machine language. In any case, the language may be a compiled or interpreted language. In addition, the program may be run on a programmed ASIC for this purpose. In addition, the operation of the process described in the present invention may be performed in any suitable order, unless the present invention otherwise indicates or otherwise clearly contradicts the context. The process described in the present invention (or variations and / or combinations thereof) may be performed under the control of one or more computer systems configured with executable instructions, and may be implemented as a code (e.g., executable instructions, one or more computer programs, or one or more applications) executed on one or more processors in common, by hardware or a combination thereof. The computer program includes a plurality of instructions that may be executed by one or more processors.

[0085] Further, the method can be implemented in any type of computing platform that is operably connected to a suitable computer, including but not limited to a personal computer, a minicomputer, a mainframe, a workstation, a network or distributed computing environment, a separate or integrated computer platform, or in communication with a charged particle tool or other imaging device, etc. Various aspects of the present invention can be implemented in machine-readable code stored on a non-transitory storage medium or device, whether removable or integrated into a computing platform, such as a hard disk, an optical read and / or write storage medium, a RAM, a ROM, etc., so that it can be read by a programmable computer, and when the storage medium or device is read by the computer, it can be used to configure and operate the computer to perform the process described herein. In addition, the machine-readable code, or portions thereof, can be transmitted via a wired or wireless network. When such media includes instructions or programs that implement the steps described above in conjunction with a microprocessor or other data processor, the invention described in the present invention includes these and other different types of non-transitory computer-readable storage media. When programmed according to the methods and techniques of the present invention, the present invention also includes the computer itself.

[0086] The above description is only an embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for detecting memory leaks, characterized in that: The method includes: During the process running, each time a memory application is successfully made from the heap, the memory space information of the successful application is added to the allocated memory set; each time a piece of memory that is no longer in use is successfully released, the released memory space information is deleted from the allocated memory set; After the process is started, the heap space of the process is scanned regularly, and the memory with reference relationship is put into the referenced memory set; After scanning the heap space of the process and building the referenced memory set, the memory space that exists in the allocated memory set but does not exist in the referenced memory set is identified as leaked memory.

2. The method according to claim 1, characterized in that The allocated memory set adopts a linked list structure. The linked list structure unit stores memory space information in the form of a two-tuple of offset address and memory space size, and is organized into a linked list structure by sorting the starting offset address of the memory space from small to large.

3. The method according to claim 1, characterized in that The method of periodically scanning the heap space of the process and putting the memory with reference relationship into the referenced memory set is: After the process is initialized, read the memory scan timer interval configuration; When the memory scan timer interval value is not zero, the memory leak detection function is enabled and the memory scan timer is started; After the memory scan timer times out, it starts traversing the data segment space of the process; Traverse the memory content in the data segment space. If the memory content contains a heap address and the heap address is in the allocated memory set, the memory space pointed to by the heap address is used as the first-level reference memory and its memory space information is stored in the referenced memory set. Traverse the first-level reference memory. If its content contains a heap address and the heap address is in the allocated memory set, the memory space pointed to by the heap address is used as the second-level reference memory and its memory space information is stored in the referenced memory set. The newly added hierarchical reference memory is traversed in sequence until there is no reference memory in the current hierarchical reference memory. The traversal ends and the final referenced memory set is obtained.

4. The method according to claim 3, characterized in that When there is a situation where the upper-level reference memory references the lower-level reference memory, and the lower-level reference memory references the upper-level reference memory, when traversing to the lower-level reference memory, its reference relationship to the upper-level reference memory is ignored.

5. The method according to claim 4, characterized in that The method is applied to the Linux operating system.

6. A device for detecting memory leakage, characterized in that: The device includes: The allocated memory set maintenance module is used to add the successfully applied memory space information to the allocated memory set each time a memory application is successfully made from the heap during the process running; each time a piece of memory that is no longer used is successfully released, the released memory space information is deleted from the allocated memory set; The referenced memory set maintenance module is used to periodically scan the heap space of the process after the process is started, and put the memory with reference relationship into the referenced memory set; The leak memory identification module is used to identify the memory space that exists in the allocated memory set but not in the referenced memory set as leak memory after scanning the heap space of the process and building the referenced memory set.

7. The device according to claim 6, characterized in that The allocated memory set adopts a linked list structure. The linked list structure unit stores memory space information in the form of a two-tuple of offset address and memory space size, and is organized into a linked list structure by sorting the starting offset address of the memory space from small to large.

8. The device according to claim 6, characterized in that The referenced memory set maintenance module includes: The configuration reading module is used to read the memory scan timer interval configuration after the process is initialized; when the memory scan timer interval value is not zero, the memory leak detection function is enabled and the memory scan timer is started; The timing scanning module is used to start traversing the data segment space of the process after the memory scanning timer times out; Traverse the memory content in the data segment space. If the memory content contains a heap address and the heap address is in the allocated memory set, the memory space pointed to by the heap address is used as the first-level reference memory and its memory space information is stored in the referenced memory set. Traverse the first-level reference memory. If its content contains a heap address and the heap address is in the allocated memory set, the memory space pointed to by the heap address is used as the second-level reference memory and its memory space information is stored in the referenced memory set. The newly added hierarchical reference memory is traversed in sequence until there is no reference memory in the current hierarchical reference memory. The traversal ends and the final referenced memory set is obtained.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a storage medium and a communication bus, wherein the processor, the communication interface and the storage medium communicate with each other via the communication bus; Storage medium for storing computer programs; A processor, for implementing the method according to any one of claims 1 to 5 when executing a computer program stored on a storage medium.

10. A storage medium having a computer program stored thereon, characterized in that: The computer program implements the method of any one of claims 1 to 5 when executed by a processor.