Periodic memory leak detection method, device and system

By generating a full pointer list and filtering the sub-pointer list with regular growth in timestamps, the problems of low memory leak detection efficiency and insufficient precision in the existing technology are solved, and efficient and accurate memory leak detection is achieved.

CN119807012AActive Publication Date: 2025-04-11HANGZHOU TUYA INFORMATION TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411906678.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-04-11
Estimated Expiration
2044-12-23

AI Technical Summary

Technical Problem

The prior art is inefficient in detecting periodic memory leaks and it is difficult to accurately identify leaked locations, especially when memory leaked locations cannot be predicted in advance.

Method used

By counting memory applications, a full pointer list is generated, including contextual features such as timestamps, memory application lengths, memory application call functions and thread names. Fields with the same characteristics are divided into sub-pointer lists, and a target pointer list with the timestamps regularly grow. Then, through a communication protocol with the second electronic device, the target pointer list and memory data are transmitted to the second electronic device to determine whether there is a pointer value of memory leaks.

Benefits of technology

It improves the accuracy and efficiency of memory leak detection, can accurately identify periodic memory leaks, reduces the operating pressure of the first electronic device, and ensures its operating efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807012A_ABST
    Figure CN119807012A_ABST
Patent Text Reader

Abstract

The invention provides a detection method, device and system applied to periodic memory leak, the method is applied to first electronic equipment, a full pointer list is generated by counting memory applications, and the full pointer list comprises a first feature and a second feature. And dividing the records with the same second feature into sub pointer lists, and further determining a target pointer list set of which the timestamps are regularly increased. And transmitting the target pointer list and the memory data through a communication protocol with the second electronic equipment so as to identify a memory leak pointer value. According to the method, the first electronic equipment can effectively screen and transmit the target pointer list and the memory data to the second electronic equipment, the pointer list with the timestamps increasing regularly is analyzed in a centralized mode, the timestamps increasing regularly are obvious marks of memory leakage in a period, the accuracy and efficiency of detection are improved, and the detection efficiency is improved. And the specific analysis part is performed at the second electronic equipment end, so that the operation pressure of the first electronic equipment is reduced, and the operation efficiency of the first electronic equipment is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] Invention Name

[0002] The present application relates to the field of computers, and in particular to a memory leak detection method, device and system. Background Art

[0003] Memory leak refers to a program applying for dynamic storage space from the system, but failing to release the applied memory space after use, causing the system to be unable to reclaim the memory in time and allocate it to other programs. Since computer system memory resources are limited, memory leaks can cause high system memory usage, resulting in a waste of resources, slowing down the system and even causing the system to crash. According to the leakage pattern, it can be divided into single leaks and periodic leaks. Single leaks occur when a program allocates memory but does not release it, but this only happens once. Since the amount of leaked memory is usually fixed, the long-term impact on the system is relatively small. Periodic leaks occur when a program leaks memory every time it performs an operation or scheduled task. Over time, this type of leak will cause the available memory to gradually decrease until the system memory is exhausted, which may eventually lead to system performance degradation or even system crash.

[0004] In the related art, the monitoring method for periodic leaks requires presetting the object of interest and collecting all pointer variables in the target area; that is, it is necessary to collect stack information in advance. However, in most cases, the location of the memory leak cannot be predicted in advance, and the method of collecting stack information in advance is relatively cumbersome, inefficient in use, and has high requirements on device performance. Summary of the invention

[0005] Based on this, it is necessary to propose a method, device and system that can efficiently and accurately detect memory leaks.

[0006] In a first aspect, the present application provides a detection method for periodic memory leaks, which is applied to a first electronic device. The method includes:

[0007] Counting memory applications and generating a full pointer list, wherein the full pointer list includes a plurality of fields, each field includes a context feature of each memory application, the context feature includes a first feature and a second feature, the first feature and the second feature each include at least one sub-feature, the first feature includes at least a timestamp, and the second feature includes at least a memory application length, a memory application calling function, and a thread name;

[0008] The fields with the same second characteristic in the full pointer list are grouped into one group to generate N groups of sub-pointer lists; wherein any group of sub-pointer lists includes at least one field;

[0009] Determine a target pointer list set; wherein the target pointer list set includes at least one target pointer list, and the target pointer list is a sub-pointer list whose timestamp increases regularly;

[0010] Based on the communication protocol with the second electronic device, at least part of the target pointer list in the target pointer list set and the memory data are transmitted to the second electronic device on the first electronic device side, so that the second electronic device determines whether there is a pointer value of a memory leak based on the pointer value in the field of the target pointer list and the memory data.

[0011] In one embodiment, determining the target pointer list includes:

[0012] For any sub-pointer list, count the timestamps in the sub-pointer list to generate a timestamp list corresponding to the sub-pointer list, where the timestamp list corresponding to the sub-pointer list includes multiple timestamps;

[0013] For any timestamp list, determine whether the timestamps in the timestamp list increase regularly;

[0014] The sub-pointer lists corresponding to the timestamp lists whose timestamps increase regularly are taken as the target pointer lists, and the target pointer list set is determined based on each target pointer list.

[0015] In one embodiment, for any timestamp list, determining whether the timestamps in the timestamp list increase regularly includes:

[0016] For any timestamp list, determine the time length corresponding to the timestamp list, wherein the time length is the difference between the maximum value corresponding to the latest timestamp in the timestamp list and the minimum value corresponding to the minimum timestamp;

[0017] Sort each timestamp list based on the length of time corresponding to each timestamp list;

[0018] Starting from the timestamp list with the largest time length, determine in turn whether the timestamps in each timestamp list increase regularly.

[0019] In one embodiment, for any timestamp list, in order to determine whether the timestamps in the timestamp list increase regularly, the process includes:

[0020] For any timestamp list, determine the number of timestamps in each timestamp list;

[0021] Sort each timestamp list based on the number of timestamps corresponding to each timestamp list;

[0022] Starting from the timestamp list with the largest number of timestamps, determine in turn whether the timestamps in each timestamp list increase regularly.

[0023] In one embodiment, the timestamp increases regularly, including at least one of the following:

[0024] Timestamps increase in an arithmetic progression;

[0025] The timestamp increases periodically.

[0026] The intervals between timestamps gradually increase;

[0027] The intervals between timestamps gradually decrease.

[0028] In one embodiment, the fields with the same second characteristic in the full pointer list are grouped into one group to generate N groups of sub-pointer lists, including:

[0029] Using the second feature as the index, search the full pointer list;

[0030] The fields with the same second characteristic in the full pointer list are matched into a group to generate N groups of sub-pointer lists.

[0031] In one embodiment, the second electronic device determines whether there is a pointer value of a memory leak according to the pointer value in the field of the target pointer list and the memory data, including:

[0032] The second electronic device determines whether there is a pointer value of memory leakage according to the pointer value in the field of the target pointer list and the memory data, and the second electronic device can extract the pointer value in the field of the target pointer list according to any received target pointer list, and define the extracted pointer value as the target pointer value;

[0033] The second electronic device searches the memory data to determine whether there is an object matching the target pointer value in the memory data for any search object;

[0034] The second electronic device is enabled to mark the target pointer value retrieved without a matching object as a memory leak pointer value, and generate a memory leak pointer list based on each memory leak pointer value.

[0035] In one embodiment, the method further comprises:

[0036] Determine the code segment list by finding the start and end addresses of the code segment in the link script;

[0037] At the current code calling position, the addresses that match the code segment list are polled and retrieved in sequence from the top of the stack to the bottom of the stack. The retrieved addresses form a callstack. At the current code calling position, the current thread name, memory request calling function and request length are obtained according to the context of the current code. Based on the three data, it is determined whether there is a second feature in the memory leak pointer list that matches the current thread name, memory request calling function and request length.

[0038] In a second aspect, the present application provides a detection device for periodic memory leaks. The device is applied to a first electronic device, including:

[0039] A first generating module is used to count memory applications and generate a full pointer list, wherein the full pointer list includes multiple fields, each field includes context features of each memory application, the context features include a first feature and a second feature, the first feature and the second feature each include at least one sub-feature, the first feature includes at least a timestamp, and the second feature includes at least a memory application length, a memory application calling function, and a thread name;

[0040] The second generating module is used to group the fields with the same second characteristic in the full pointer list into a group to generate N groups of sub-pointer lists; wherein any group of sub-pointer lists includes at least one field; the first generating module is also used to determine a target pointer list set; wherein the target pointer list set includes at least one target pointer list, and the target pointer list is a sub-pointer list whose timestamp increases regularly;

[0041] A transmission module is used to transfer at least part of the target pointer list in the target pointer list set and memory data to the second electronic device based on the communication protocol between the first electronic device and the second electronic device, so that the second electronic device determines whether there is a pointer value of a memory leak based on the pointer value in the field of the target pointer list and the memory data.

[0042] In a third aspect, the present application provides a detection system for periodic memory leaks. The detection system includes a first electronic device and a second electronic device;

[0043] The first electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of the method for detecting periodic memory leaks in the first aspect when executing the computer program.

[0044] The above-mentioned detection method, device and system for periodic memory leaks are applied to a first electronic device, and a full pointer list is generated by counting memory applications. The full pointer list includes multiple fields, and each field includes context features. The context features include a first feature and a second feature. The first feature includes at least a timestamp, and the second feature includes at least a memory application length, a memory application call function, and a thread name. Fields with the same second feature are divided into sub-pointer lists, and a target pointer list set with a regularly growing timestamp is determined. Through a communication protocol with a second electronic device, the target pointer list and memory data are transmitted to identify the memory leak pointer value. The first electronic device can effectively screen and transmit the target pointer list and memory data to the second electronic device. Since the method focuses on analyzing the pointer list with a regularly growing timestamp, the regularly growing timestamp is an obvious sign of memory leakage within a period, the accuracy and efficiency of the detection are improved, and the specific analysis part is performed on the second electronic device, which effectively reduces the operating pressure of the first electronic device and ensures the operating efficiency of the first electronic device. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for describing the embodiments.

[0046] Figure 1 An application environment diagram for detecting periodic memory leaks in one embodiment;

[0047] Figure 2 A flowchart of a method for detecting periodic memory leaks in one embodiment;

[0048] Figure 3 A flowchart of determining a target pointer list set in one embodiment;

[0049] Figure 4 A schematic diagram of a full pointer list, N groups of sub-pointer lists, and a target pointer list set in one embodiment;

[0050] Figure 5 A flowchart for determining whether timestamps in a timestamp list increase regularly in one embodiment;

[0051] Figure 6 A flowchart for determining whether the timestamps in the timestamp list increase regularly in another embodiment;

[0052] Figure 7 A flowchart of generating N groups of sub-pointer lists in one embodiment;

[0053] Figure 8 A flowchart of a pointer value for determining whether a memory leak exists in one embodiment;

[0054] Fig. 9 A flowchart of finding a pointer application source causing a memory leak in one embodiment;

[0055] Fig.10 is a module diagram of a detection device for periodic memory leaks in one embodiment;

[0056] Fig.11 A module diagram of a detection system for periodic memory leaks in one embodiment. DETAILED DESCRIPTION

[0057] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution of the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments of the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0058] In the computer field, memory management is always a crucial topic. Memory management includes stack memory management and heap memory management.

[0059] Stack memory is a memory area in a computer used to store function calls and local variables. It is mainly used to manage context information during function calls, including local variables, function parameters, and return addresses. Stack memory is automatically allocated and released by the computer system and managed by the compiler.

[0060] Heap memory is mainly used to store data other than stack memory, such as global variables and newly created objects. It is a memory space dynamically allocated by electronic devices during the running of a process. The process of an electronic device can flexibly allocate the required space in the heap memory by calling a special memory allocation function. When the allocated heap memory is no longer needed, the process can also effectively return these memory resources to the system by calling the corresponding memory release function. Based on this feature, heap memory is prone to memory leaks.

[0061] The present application provides a method for detecting periodic memory leaks, which can be applied to Figure 1In the application environment shown. Among them, the terminal 101 communicates with the server 102 through the network, and the terminal 101 can also communicate with the server 102 through a wired interface (such as a uart interface). Among them, the terminal 101 can be a first electronic device, and the server 102 is a second electronic device. It should be noted that the terminal 101 can also be a second electronic device, and the server 102 is a first electronic device. In this embodiment, the terminal 101 is the first electronic device and the server 102 is the second electronic device. For example, the terminal 101 is the first electronic device and the server 102 is the second electronic device. Specifically, the terminal 101 counts the memory applied for and generates a full pointer list, wherein the full pointer list includes multiple fields, each field includes context features at each memory application, and the context features include a first feature and a second feature. The fields with the same second feature in the full pointer list are grouped together, and N groups of sub-pointer lists are generated and screened to obtain a sub-pointer list set whose timestamps show regular growth. Based on the communication protocol, the target sub-pointer list and the memory data of the entire terminal 101 (which can be composed of the bss segment of the current program, the global data segment and the static data segment, and the stack memory of all tasks) are all transmitted to the server 102, and the pointer value of the sub-pointer list is intercepted by the server 102, and the pointer value is retrieved in the memory data. If it cannot be retrieved, it is considered that there is a memory leak in the pointer value. Exemplarily, the pointer value of the intercepted sub-pointer list is 0x12345678, and it is necessary to search in the memory data whether there is 0x12345678 stored in the big endian or little endian format. If it exists, it means that the pointer is being referenced, and it can be considered that there is no memory leak; if it does not exist, it means that the pointer has no reference, and it can be considered that the pointer can no longer be used, and it can be determined as a memory leak. Among them, the terminal 101 can be but not limited to various personal computers, laptops, smart phones, tablet computers, Internet of Things devices, etc. The server 102 can be implemented with an independent server or a server cluster consisting of multiple servers.

[0062] In one embodiment, Figure 2 As shown, a method for detecting periodic memory leakage applied to a first electronic device is provided, the method comprising the following steps:

[0063] Step 201: Count memory applications and generate a full pointer list, wherein the full pointer list includes multiple fields, each field includes context features of each memory application, the context features include a first feature and a second feature, the first feature and the second feature each include at least one sub-feature, the first feature includes at least a timestamp, and the second feature includes at least a memory application length, a memory application calling function, and a thread name;

[0064] Specifically, the first electronic device can be various personal computers, laptops, smart phones, tablet computers, Internet of Things devices, etc., which need to run for a long time and have high requirements for stability and performance. These devices are more susceptible to memory leaks. When the first electronic device needs to apply for memory, the first electronic device will record the fields of the current application, which includes the context features of the memory application. The context features can be used to represent some information of the current memory application. It should be noted that the first feature in the context feature can include a timestamp, etc., and the second feature in the context feature can include the length of the memory application, the memory application calling function, and the thread name, etc.; in addition, the context feature also includes a pointer value. After obtaining all the required field information, create a table structure and store all pointer information in the table to generate a full pointer list.

[0065] Step 202: Group the fields with the same second characteristic in the full pointer list into one group to generate N groups of sub-pointer lists; wherein any group of sub-pointer lists includes at least one field;

[0066] Specifically, the second feature can be used as a grouping basis to group the fields with the same second feature in the full pointer list into a group of sub-pointer lists, generating a total of N groups of sub-pointer lists. Any group of generated sub-pointer lists contains at least one field, ensuring that each group of sub-pointer lists has sufficient information for subsequent analysis.

[0067] Step 203: determining a target pointer list set; wherein the target pointer list set includes at least one target pointer list, and the target pointer list is a sub-pointer list whose timestamp increases regularly;

[0068] Specifically, a timestamp analysis is performed on each group of sub-pointer lists to identify which groups of sub-pointer lists have timestamps that grow in a regular manner. It should be noted that it is specified in advance what time intervals or growth patterns are considered regular. For example, if the difference between timestamps is always a fixed value or follows a predictable pattern (such as an arithmetic progression), it is considered that the timestamps grow in a regular manner. Traverse all sub-pointer lists and filter out sub-pointer lists whose timestamps meet the regular growth criteria. These sub-pointer lists will be marked as target pointer lists. All filtered target pointer lists are aggregated to form a target pointer list set. Among them, the target pointer list set includes at least one target pointer list.

[0069] Step 204: Based on the communication protocol with the second electronic device, at the first electronic device end, at least part of the target pointer list in the target pointer list set and the memory data are transmitted to the second electronic device, so that the second electronic device determines whether there is a pointer value of a memory leak based on the pointer value in the field of the target pointer list and the memory data.

[0070] Specifically, first determine the communication protocol to be used between the first electronic device and the second electronic device. This may be a network-based protocol (such as HTTP, FTP, SSH, etc.), a serial communication protocol (such as UART, RS-232, etc.), or any other applicable communication protocol. Select at least one target pointer list and related memory data from the target pointer list set and prepare for transmission. These data may include pointer values, timestamps, memory application lengths, etc. Establish a communication connection with the second electronic device on the first electronic device to ensure that the data can be sent successfully. After receiving the data, the second electronic device analyzes the pointer values ​​and memory data in the target pointer list to determine whether there is a pointer value that indicates a memory leak.

[0071] The above-mentioned method for periodic memory leak detection generates a full pointer list by counting memory applications, and divides the fields with the same second feature in the full pointer list into a group to generate N groups of sub-pointer lists; and uses the sub-pointer list with a regularly growing timestamp as the target pointer list, and aggregates the target pointer list to form a target pointer list set; based on the communication protocol with the second electronic device, at least part of the target pointer list and memory data in the target pointer list set are transmitted to the second electronic device, so that the second electronic device determines whether there is a pointer value of memory leakage according to the pointer value in the field of the target pointer list and the memory data. The first electronic device can effectively screen and transmit the target pointer list and memory data to the second electronic device. Since the method focuses on analyzing the pointer list with a regularly growing timestamp, and the regularly growing timestamp is an obvious sign of memory leakage within the period, the accuracy and efficiency of the detection are improved, and the specific analysis part is carried out at the second electronic device end, which effectively reduces the operating pressure of the first electronic device and ensures the operating efficiency of the first electronic device.

[0072] In one embodiment, Figure 3 As shown, determining the target pointer list set includes the following steps:

[0073] Step 301: for any sub-pointer list, count the timestamps in the sub-pointer list to generate a timestamp list corresponding to the sub-pointer list, where the timestamp list corresponding to the sub-pointer list includes multiple timestamps;

[0074] Specifically, for any group of sub-pointer lists, statistics are collected according to the timestamps in the sub-pointer lists to generate a timestamp list corresponding to the sub-pointer lists. It can be understood that each group of sub-pointer lists corresponds to a group of timestamp lists.

[0075] Step 302: for any timestamp list, determine whether the timestamps in the timestamp list increase regularly;

[0076] Specifically, for any set of timestamp lists, set a criterion to determine whether the timestamps are growing regularly, including whether the difference is always a fixed value or follows a predictable pattern (arithmetic or geometric progression, etc.). For each timestamp in the timestamp list, calculate the time interval between it and the previous timestamp. Check whether the calculated time interval meets the criterion for regular growth. If the time interval is consistent or follows a predictable pattern, the timestamps are considered to be growing regularly.

[0077] For example, suppose we have a timestamp list containing the following timestamps: timestamp list = [2024-11-2010:00:00, 2024-11-20 10:05:00, 2024-11-20 10:10:00, 2024-11-2010:15:00].

[0078] Calculate the time intervals: First interval: 2024-11-20 10:05:00-2024-11-20 10:00:00 = 5 minutes. Second interval: 2024-11-20 10:10:00-2024-11-20 10:05:00 = 5 minutes. Third interval: 2024-11-20 10:15:00-2024-11-20 10:10:00 = 5 minutes. All time intervals are 5 minutes, which is a constant interval, indicating that the timestamps increase regularly.

[0079] Another example is: t1, t2, t3, t1+2, t2+2, t3+2, t1+4, t2+4, t3+4. Among them, t1, t2, t3 are irregular, but t1, t2, t3, t1+2, t2+2, t3+2, t1+4, t2+4, t3+4 will cycle periodically, and the difference is 2.

[0080] Step 303: taking the sub-pointer lists corresponding to the timestamp lists whose timestamps increase regularly as target pointer lists, and determining the target pointer list set based on each target pointer list.

[0081] Specifically, at the first electronic device end, the sub-pointer list corresponding to the timestamp list with regularly increasing timestamps is used as the target pointer list, and is output as {P1, P2, ..., P n For example, if there are N groups of sub-pointer lists corresponding to N groups of timestamp lists, and 10 groups of corresponding timestamp lists meet the condition of regular growth, then these 10 groups of sub-pointer lists are marked as having possible memory leaks. 10} corresponds to the target pointer set of these 10 groups of sub-pointer lists.

[0082] In this embodiment, by counting the timestamps in each group of sub-pointer lists to generate a corresponding timestamp list, and analyzing these timestamp lists to determine whether the timestamps show regular growth, the sub-pointer lists with regular growth of timestamps are used as target pointer lists, and the target pointer list set is determined based on these target pointer lists. This method improves the pertinence and accuracy of detection, and the specific effect is that it can accurately identify those sub-pointer lists with regular growth of timestamps from a large number of memory application records, thereby effectively screening out potential periodic memory leaks.

[0083] It should be noted that if Figure 4 As shown. The full pointer list contains multiple fields, each field includes the context features of each memory application, the context features include the first feature and the second feature, the first feature includes the timestamp; the second feature includes the application length, the memory application calling function and the current thread name. Each field in the figure has its own corresponding first feature and second feature. In this embodiment, the full pointer list contains 15 fields.

[0084] The sub-pointer list is generated by grouping the fields with the same second characteristic in the full pointer list, that is, the sub-pointer list is generated with "length, memory application calling function, current thread name" as the index, and a total of N groups of sub-pointer lists are generated. In this embodiment, 5 groups of sub-pointer lists are generated, the first group of sub-pointer lists includes fields 1, 3, and 5; the second group of sub-pointer lists includes fields 2, 4, and 6; the third group of sub-pointer lists includes fields 7, 9, and 11; the fourth group of sub-pointer lists includes fields 8, 10, and 12; and the fifth group of sub-pointer lists includes fields 13, 14, and 15.

[0085] The target pointer list is to generate a timestamp list corresponding to the sub-pointer list according to the timestamp in each group of sub-pointer lists, and take the sub-pointer list corresponding to the timestamp list whose timestamp increases regularly as the target pointer list, and determine the target pointer list set based on each target pointer list. In this embodiment, if the timestamps in the sub-pointer lists corresponding to the first, third and fourth groups of timestamp lists increase regularly, the first, third and fourth groups of sub-pointer lists are taken as the target pointer lists, and the target pointer list set is determined based on these three groups of target pointer lists.

[0086] In one embodiment, Figure 5 As shown, for any timestamp list, determining whether the timestamps in the timestamp list increase regularly includes the following steps:

[0087] Step 501: for any timestamp list, determine the time length corresponding to each timestamp list, wherein the time length is the difference between the maximum value corresponding to the latest timestamp in the timestamp list and the minimum value corresponding to the minimum timestamp;

[0088] Specifically, a timestamp list is randomly selected from the timestamp lists corresponding to each group of sub-pointer lists, and the earliest and latest timestamps are found in the selected timestamp list, where the maximum value corresponding to the latest timestamp and the minimum value corresponding to the minimum timestamp are found. The difference between the maximum value corresponding to the latest timestamp and the minimum value corresponding to the minimum timestamp is calculated to obtain the time length. For each timestamp list, the time length corresponding to each timestamp list is calculated.

[0089] Assume that one of the timestamp lists contains the following timestamps, timestamp list = [2024-11-20 10:00:00, 2024-11-20 10:05:00, 2024-11-20 10:10:00, 2024-11-20 10:15:00].

[0090] Earliest timestamp: 2024-11-20 10:00:00. Latest timestamp: 2024-11-20 10:15:00. Time length: The difference between the earliest and latest timestamps is 15 minutes.

[0091] Step 502: sorting each time stamp list based on the length of time corresponding to each time stamp list;

[0092] Specifically, for each timestamp list, the time length corresponding to each timestamp list is calculated, that is, the difference between the latest timestamp and the earliest timestamp in each timestamp list is calculated. Each calculated timestamp list and its corresponding time length are sorted in order of size, which can be sorted from large to small in terms of time length.

[0093] Step 503: Starting from the timestamp list with the largest time length, determine in turn whether the timestamps in each timestamp list increase regularly.

[0094] Specifically, according to step 502, a timestamp list is obtained that is sorted from largest to smallest in terms of time length. Starting from the timestamp list with the largest time length, check whether the timestamps therein are growing regularly. This can be done by calculating the intervals between consecutive timestamps and checking whether these intervals are consistent or follow a certain pattern. After completing the check of the timestamp list with the largest time length, continue to perform the same check on the timestamp list with the next time length in the sorting until all timestamp lists have been checked. Record the check result of each timestamp list to determine which timestamp lists have regularly growing timestamps.

[0095] In this embodiment, the time length is determined by calculating the difference between the earliest and latest timestamps in each timestamp list, and all timestamp lists are sorted based on these time lengths. Then, starting from the list with the longest time length, it is checked in turn whether the timestamps in each list show a regular growth, thereby effectively identifying periodic memory leaks.

[0096] In one embodiment, Figure 6 As shown, for any timestamp list, determining whether the timestamps in the timestamp list increase regularly includes:

[0097] Step 501: for any timestamp list, determine the number of timestamps in each timestamp list;

[0098] Specifically, a timestamp list is randomly selected from the timestamp lists corresponding to each group of sub-pointer lists, and the number of timestamps included in the selected timestamp list is counted to count the number of timestamps included in the timestamp list. For each timestamp list, the number of timestamps in each timestamp list is counted.

[0099] Assume a timestamp list including the following timestamps, timestamp list = [2024-11-2010:00:00, 2024-11-20 10:05:00, 2024-11-20 10:10:00, 2024-11-20 10:15:00]. The timestamp list includes 4 timestamps.

[0100] Step 602: sorting each time stamp list based on the quantity of timestamps corresponding to each time stamp list;

[0101] Specifically, for each timestamp list, the number of timestamps in each timestamp list is counted, and the timestamps in each timestamp list obtained by counting are mathematically sorted by size, which can be sorted from large to small in terms of the number of timestamps.

[0102] Step 603: Starting from the timestamp list with the largest number of timestamps, determine in turn whether the timestamps in each timestamp list increase regularly.

[0103] Specifically, according to step 602, a timestamp list is obtained that is sorted from large to small in terms of the number of timestamps. Starting from the timestamp list with the largest number of timestamps, check whether the timestamps therein are increasing regularly. This can be done by calculating the intervals between consecutive timestamps and checking whether these intervals are consistent or follow a certain pattern. After completing the check of the timestamp list with the largest number of timestamps, continue to perform the same check on the timestamp list with the next number of timestamps in the sort until all timestamp lists have been checked. Record the check results of each timestamp list to determine which timestamp lists have timestamps that are increasing regularly.

[0104] In this embodiment, by counting the number of timestamps in each timestamp list and sorting the timestamp lists based on the number of timestamps, starting with the list with the largest number of timestamps, the timestamps in each timestamp list are analyzed in turn to see whether they show a regular growth, so as to identify periodic memory leaks, thereby improving the efficiency and accuracy of detecting periodic memory leaks.

[0105] In one embodiment, to determine whether the timestamps in the timestamp list show regular growth, one of the following dimensions may be considered: the timestamps grow in an arithmetic progression, the timestamps grow in a periodic cycle, the intervals between timestamps gradually increase, or the intervals between timestamps gradually decrease.

[0106] Specifically, the timestamps grow in an arithmetic progression, and it is checked whether the difference between consecutive timestamps is constant. If the time difference between any two consecutive timestamps is equal, then the timestamps grow in an arithmetic progression; the timestamps grow in a periodic cycle, and it is analyzed whether there is a fixed cycle for the timestamps so that the timestamps grow in this cycle, even if the amount of growth each time may be different; the interval between timestamps gradually increases, and it is observed whether the interval between timestamps has an increasing trend, that is, as time goes by, the time interval for each memory request gradually becomes longer; the interval between timestamps gradually decreases, and it is checked whether the interval between timestamps has a decreasing trend, that is, as time goes by, the time interval for each memory request gradually becomes shorter.

[0107] Assume a timestamp list, timestamp list = [2024-11-20 10:00:00, 2024-11-2010:03:00, 2024-11-20 10:06:00, 2024-11-20 10:12:00].

[0108] The timestamps increase in an arithmetic progression: the calculation intervals are 3 minutes, 3 minutes, and 6 minutes. The timestamps do not increase in an arithmetic progression.

[0109] Timestamps increase in a cyclical pattern: Observe whether there is a repeating pattern, such as a long gap after every 3 requests. In this example, it is not easy to identify an obvious cyclical pattern.

[0110] The interval between timestamps increases gradually: Check whether the time interval increases with time: 3 minutes, 3 minutes, 6 minutes. The time interval increases gradually, which meets the condition of the interval increasing gradually.

[0111] The interval between timestamps is gradually decreasing: Since the time interval is gradually increasing, the condition of the interval being gradually decreasing is not met.

[0112] In this embodiment, regular growth is identified by checking the timestamp list, specifically including checking whether the timestamps grow in an arithmetic progression, whether they grow in a periodic cycle, and whether the intervals gradually increase or decrease. If at least one of these conditions is met, the timestamps can be considered to grow regularly. This method uses multiple conditions to determine whether the timestamp list grows regularly, and at least one of them must be met to satisfy the condition that the timestamps grow regularly, thereby effectively identifying periodic memory leaks.

[0113] In one embodiment, Figure 7 As shown, the fields with the same second characteristic in the full pointer list are grouped into one group to generate N groups of sub-pointer lists, including the following steps:

[0114] Step 701: Using the second feature as an index, search the full pointer list;

[0115] Specifically, in the full pointer list, a search is performed based on the second feature (memory request length, memory request calling function, and thread name) as an index to find out fields with the same second feature.

[0116] Step 702: Match the fields with the same second characteristic in the full pointer list into a group to generate N groups of sub-pointer lists.

[0117] Specifically, after the first electronic device obtains the full pointer list, the application length, the calling function of the memory application, and the thread name are used as indexes to find fields with the same characteristics. The fields with the same second characteristic in the search results are grouped together to form a group of sub-pointer lists. A total of N groups of sub-pointer lists are generated.

[0118] In this embodiment, N groups of sub-pointer lists are generated by grouping the fields with the same second feature in the full pointer list. Specifically, the full pointer list is searched with the second feature as an index, where the second feature includes the memory application length, the memory application calling function, and the thread name; the fields with the same second feature are matched into a group to form a group of sub-pointer lists, and a total of N groups of sub-pointer lists are generated. This method can centrally analyze fields with the same second feature, improve the accuracy and efficiency of detecting periodic memory leaks; and group fields with the same second feature to make it easier to identify potential memory leak patterns.

[0119] In one embodiment, Figure 8 As shown, the second electronic device determines whether there is a pointer value of memory leakage according to the pointer value in the field of the target pointer list and the memory data, including the following steps:

[0120] Step 801: enabling the second electronic device to extract a pointer value in a field of a target pointer list according to any received target pointer list, and define the extracted pointer value as a target pointer value;

[0121] Specifically, based on the communication protocol between the first electronic device and the second electronic device, {P1, P2, ..., P n The target pointer list and the overall memory data are transmitted to the second electronic device. In the second electronic device, according to each received target pointer category, the target pointer list contains the filtered pointer values ​​that may be related to the memory leak.

[0122] Step 802: enabling the second electronic device to search the memory data to determine, for any target pointer value, whether there is an object matching the target pointer value in the memory data;

[0123] Specifically, the second electronic device has received the target pointer list and related memory data from the first electronic device. For each target pointer value in the target pointer list, the second electronic device searches the memory data to find out whether there is an object matching these target pointer values.

[0124] Step 803: The second electronic device is enabled to mark the target pointer value for which no matching object is retrieved as a memory leak pointer value, and generate a memory leak pointer list based on each memory leak pointer value.

[0125] Specifically, after the second electronic device completes the retrieval of the memory data, it will mark those target pointer values ​​that do not find matching objects in the memory data as memory leak pointer values. Based on all the pointer values ​​marked as memory leaks, the second electronic device will generate a memory leak pointer list, which will include all pointer values ​​suspected of memory leaks.

[0126] In this embodiment, the second electronic device extracts the pointer value from the received target pointer list as the target pointer value, and retrieves these target pointer values ​​in the memory data to determine whether there is a matching object. If the retrieval result shows that a certain target pointer value has no matching object in the memory data, it is marked as a memory leak pointer value, and a memory leak pointer list is generated based on these memory leak pointer values. This method can accurately identify pointer values ​​that may cause memory leaks, thereby improving the accuracy and efficiency of memory leak detection. By generating a memory leak pointer list, memory leak problems can be quickly located and resolved, and the stability and reliability of the system can be enhanced.

[0127] In one embodiment, Fig. 9 As shown, the following steps are also included:

[0128] Step 901: Find the start and end addresses of the code segments in the link script to determine the code segment list;

[0129] Specifically, after determining that the target pointer list has a memory leak, further locate the pointer application source that causes the memory leak. Define the code segment list, analyze the link script, determine the identifier of the code segment and the starting address and ending address of the code segment, and create a code segment list, which records the location of all code segments in the program.

[0130] Step 902: At the current code calling position, at the current code calling position, poll and retrieve addresses that match the code segment list from the top of the stack to the bottom of the stack, the retrieved addresses form a callstack, and at the current code calling position, obtain the current thread name, memory application calling function and application length according to the context of the current code, and determine whether there is a second feature in the memory leak pointer list that matches the current thread name, memory application calling function and application length based on the three data.

[0131] Specifically, the current code call location refers to the specific location where the program is executed to where the memory application occurs, usually where the memory application function (such as malloc or calloc) is called. The program's call stack is a last-in-first-out (LIFO) data structure. The top of the stack is the last function called in the call stack, that is, the function currently being executed; the bottom of the stack is the earliest function called in the call stack, that is, the starting point of program execution (usually the main function). Polling starts from the top of the stack and checks one by one whether there are function pointers in the stack that fall within the code segment range. If there are, add them to the call stack list. If the current thread name, memory application calling function, and application length obtained based on the context where the current code is located fall into the second feature of the memory leak pointer list (that is, there is a second feature in the memory leak pointer list that matches the current thread name, memory application calling function, and application length, where the current thread name, memory application calling function, and application length are obtained based on the context where the current code is located), output the call stack list, which helps determine the source of the memory leak based on the call stack list.

[0132] In this embodiment, the code segment list is determined by finding the start and end addresses of the code segment in the link script; at the current code call position, the second feature in the memory leak pointer list in the memory leak pointer list is polled from the top of the stack to the bottom of the stack, and it is determined whether there is a second feature in the memory leak pointer list that matches the current thread name, the memory application calling function, and the application length. This method can accurately identify which second features in the memory leak pointer list point to the actual code segment of the program, thereby excluding those second features pointing to the code segment as potential memory leak candidates, which helps to improve the accuracy of memory leak detection and reduce false positives.

[0133] Based on the same inventive concept, the embodiment of the present application also provides a detection device for periodic memory leaks involved in the above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations of one or more embodiments of the periodic memory leak detection device provided below can refer to the limitations of the periodic memory leak detection method above, and will not be repeated here.

[0134] In one embodiment, Fig.10 As shown, a detection device for periodic memory leak is provided, which is applied to a first electronic device. The detection device includes: a first generation module 1001, a second generation module 1002 and a transmission module 1003, wherein:

[0135] The first generation module 1001 is used to count memory applications and generate a full pointer list, wherein the full pointer list includes multiple fields, each field includes context features for each memory application, the context features include a first feature and a second feature, the first feature and the second feature each include at least one sub-feature, the first feature includes at least a timestamp, and the second feature includes at least a memory application length, a memory application calling function, and a thread name.

[0136] The second generation module 1002 is used to group the fields with the same second characteristic in the full pointer list into a group to generate N groups of sub-pointer lists; wherein any group of sub-pointer lists includes at least one field; the second generation module is also used to determine a target pointer list set; wherein the target pointer list set includes at least one target pointer list, and the target pointer list is a sub-pointer list whose timestamps increase regularly.

[0137] The transmission module 1003 is used to transmit at least part of the target pointer list in the target pointer list set and the memory data to the second electronic device based on the communication protocol with the second electronic device, so that the second electronic device determines whether there is a pointer value of a memory leak based on the pointer value in the field of the target pointer list and the memory data.

[0138] In one embodiment, the second generating module 1002 determines the target pointer list set, specifically for: for any sub-pointer list, counting the timestamps in the sub-pointer list, generating a timestamp list corresponding to the sub-pointer list, wherein the timestamp list corresponding to the sub-pointer list includes multiple timestamps;

[0139] For any timestamp list, determine whether the timestamps in the timestamp list increase regularly;

[0140] The sub-pointer lists corresponding to the timestamp lists whose timestamps increase regularly are taken as the target pointer lists, and the target pointer list set is determined based on each target pointer list.

[0141] In one embodiment, the second generation module 1002 determines, for any timestamp list, whether the timestamps in the timestamp list show a regular increase, specifically for: determining, for any timestamp list, the time length corresponding to the timestamp list, wherein the time length is the difference between the maximum value corresponding to the latest timestamp in the timestamp list and the minimum value corresponding to the minimum timestamp in the timestamp list; sorting each timestamp list based on the size of the time length corresponding to each timestamp list; starting from the timestamp list with the largest time length, determining in turn whether the timestamps in each timestamp list show a regular increase.

[0142] In one embodiment, the second generation module 1002 determines, for any timestamp list, whether the timestamps in the timestamp list show a regular increase, and is specifically used to: determine, for any timestamp list, the number of timestamps in the timestamp list; sort each timestamp list based on the number of timestamps corresponding to each timestamp list; and starting from the timestamp list with the largest number of timestamps, determine in turn whether the timestamps in each timestamp list show a regular increase.

[0143] In one embodiment, the timestamps increase regularly, including at least one of the following: the timestamps increase in an arithmetic progression; the timestamps increase in a periodic cycle; the intervals between the timestamps gradually increase; the intervals between the timestamps gradually decrease.

[0144] In one embodiment, the second generation module 1002 groups the fields with the same second characteristic in the full pointer list into a group to generate N groups of sub-pointer lists, which are specifically used to: search the full pointer list with the second characteristic as the index; match the fields with the same second characteristic in the full pointer list into a group to generate N groups of sub-pointer lists.

[0145] In one embodiment, the transmission module 1003 enables the second electronic device to determine whether there is a pointer value of a memory leak based on the pointer value in the field of the target pointer list and the memory data, and is specifically used to: enable the second electronic device to extract the pointer value in the field of the target pointer list based on any received target pointer list, and define the extracted pointer value as the target pointer value; enable the second electronic device to search the memory data to determine whether there is an object matching the target pointer value in the memory data for any target pointer value; enable the second electronic device to mark the target pointer value retrieved without a matching object as a memory leak pointer value, and generate a memory leak pointer list based on each memory leak pointer value.

[0146] In one embodiment, the transmission module 1003 finds the start and end addresses of the code segments in the link script to determine the code segment list; at the current code call position, the address that matches the code segment list is polled and retrieved from the top of the stack to the bottom of the stack, and the retrieved addresses form a callstack. At the current code call position, the current thread name, memory request calling function and request length are obtained according to the context of the current code, and based on the three data, it is determined whether there is a second feature in the memory leak pointer list that matches the current thread name, memory request calling function and request length.

[0147] Each module used in the periodic memory leak detection device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0148] Based on the same inventive concept, the embodiment of the present application also provides a detection system for periodic memory leaks involved in the above. The implementation scheme for solving the problem provided by the system is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiment of the periodic memory leak detection system provided below can be referred to the limitations of the periodic memory leak detection method above, and will not be repeated here.

[0149] In one embodiment, a detection system for periodic memory leaks is provided, and its specific implementation structure is as follows: Fig.11 As shown, it may specifically include a first electronic device and a second electronic device;

[0150] The first electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of a method for detecting periodic memory leaks when executing the computer program.

[0151] Furthermore, the first electronic device also includes a communication interface, a display screen and an input device connected via a system bus. Among them, the processor of the first electronic device is used to provide computing and control capabilities. The memory of the first electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the electronic device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a detection method for periodic memory leaks is implemented. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc.

[0152] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0153] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A detection method for periodic memory leaks, characterized in that: Applied to a first electronic device, the method includes: Counting memory applications and generating a full pointer list, wherein the full pointer list includes a plurality of fields, each field includes context features of each memory application, the context features include a first feature and a second feature, the first feature and the second feature each include at least one sub-feature, the first feature includes at least a timestamp, and the second feature includes at least a memory application length, a memory application calling function, and a thread name; Group the fields with the same second characteristic in the full pointer list into one group to generate N groups of sub-pointer lists; wherein any group of sub-pointer lists includes at least one field; Determine a target pointer list set; wherein the target pointer list set includes at least one target pointer list, and the target pointer list is a sub-pointer list whose timestamp increases regularly; Based on the communication protocol with the second electronic device, at least part of the target pointer list in the target pointer list set and the memory data are transmitted to the second electronic device, so that the second electronic device determines whether there is a pointer value of a memory leak based on the pointer value in the field of the target pointer list and the memory data.

2. The detection method for periodic memory leak according to claim 1, characterized in that: Determine the target pointer list set including: For any of the sub-pointer lists, counting the timestamps in the sub-pointer list to generate a timestamp list corresponding to the sub-pointer list, wherein the timestamp list corresponding to the sub-pointer list includes a plurality of timestamps; For any of the timestamp lists, determining whether the timestamps in the timestamp list increase regularly; The sub-pointer list corresponding to the timestamp list whose timestamps increase regularly is used as the target pointer list, and the target pointer list set is determined based on each of the target pointer lists.

3. The detection method for periodic memory leak according to claim 2, characterized in that: For any of the timestamp lists, determining whether the timestamps in the timestamp list increase regularly includes: For any of the timestamp lists, determine a time length corresponding to the timestamp list, wherein the time length is a difference between a maximum value corresponding to the latest timestamp in the timestamp list and a minimum value corresponding to the minimum timestamp; Sorting the timestamp lists based on the length of time corresponding to each of the timestamp lists; Starting from the timestamp list with the largest time length, it is determined in turn whether the timestamps in each timestamp list increase regularly.

4. The detection method for periodic memory leak according to claim 2, characterized in that: For any of the timestamp lists, determining whether the timestamps in the timestamp list increase regularly includes: For any of the timestamp lists, determining the number of timestamps in the timestamp list; Sorting each of the timestamp lists based on the quantity of timestamps corresponding to each of the timestamp lists; Starting from the timestamp list with the largest number of timestamps, it is determined in turn whether the timestamps in each of the timestamp lists increase regularly.

5. The detection method for periodic memory leak according to any one of claims 1 to 4, characterized in that: The timestamp increases regularly, including at least one of the following: Timestamps increase in an arithmetic progression; The timestamp increases periodically. The intervals between timestamps gradually increase; The intervals between timestamps gradually decrease.

6. The detection method for periodic memory leak according to claim 1, characterized in that: The fields with the same second characteristic in the full pointer list are grouped into one group to generate N groups of sub-pointer lists, including: Using the second feature as an index, searching the full pointer list; Fields with the same second characteristic in the full pointer list are matched into a group to generate N groups of sub-pointer lists.

7. The detection method for periodic memory leak according to claim 1, characterized in that: The method enables the second electronic device to determine whether there is a pointer value of a memory leak according to the pointer value in the field of the target pointer list and the memory data, including: enabling the second electronic device to extract a pointer value in a field of any received target pointer list according to the target pointer list, and define the extracted pointer value as a target pointer value; causing the second electronic device to search the memory data to determine, for any target pointer value, whether there is an object matching the target pointer value in the memory data; The second electronic device is enabled to mark the target pointer value for which no matching object is retrieved as a memory leak pointer value, and generate a memory leak pointer list based on each memory leak pointer value.

8. The detection method for periodic memory leak according to claim 7, characterized in that: The method further comprises: Determine the code segment list by finding the start and end addresses of the code segment in the link script; At the current code calling position, addresses matching the code segment list are retrieved in sequence from the top of the stack to the bottom of the stack, the retrieved addresses form a callstack, and at the current code calling position, the current thread name, memory application calling function and application length are obtained according to the context of the current code, and based on the three data, it is determined whether there is a second feature in the memory leak pointer list that matches the current thread name, memory application calling function and application length.

9. A detection device for periodic memory leaks, characterized in that: Applied to a first electronic device, the device comprises: A first generating module is configured to count memory applications and generate a full pointer list, wherein the full pointer list includes a plurality of fields, each field includes a context feature of each memory application, the context feature includes a first feature and a second feature, the first feature and the second feature each include at least one sub-feature, the first feature includes at least a timestamp, and the second feature includes at least a memory application length, a memory application calling function, and a thread name; A second generating module is used to group the fields with the same second characteristic in the full pointer list into a group to generate N groups of sub-pointer lists; wherein any group of sub-pointer lists includes at least one field; the second generating module is also used to determine a target pointer list set; wherein the target pointer list set includes at least one target pointer list, and the target pointer list is a sub-pointer list whose timestamp increases regularly; A transmission module is used to transfer at least part of the target pointer list in the target pointer list set and the memory data to the second electronic device based on the communication protocol with the second electronic device, so that the second electronic device determines whether there is a pointer value of a memory leak based on the pointer value in the field of the target pointer list and the memory data.

10. A detection system for periodic memory leaks, characterized in that: The detection system includes a first electronic device and a second electronic device; The first electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the steps of the detection method for periodic memory leaks described in any one of claims 1 to 8 when executing the computer program.

Citation Information

Patent Citations

  • Memory leak detection method and device

    CN104516817A

  • Memory leak detection method and device, equipment and storage medium

    CN115952088A

  • Memory monitoring method and system

    CN116204378A

  • Memory monitoring method and device

    CN118708388A

  • Detecting Dangling Pointers and Memory Leaks Within Software

    US20080301646A1