Memory leak detection method and device, equipment and storage medium
By analyzing memory data in real time and calculating the average growth rate, the problem of memory leakage cannot be accurately detected in the existing technology, and the accurate, rapid and real-time detection of memory leakage is achieved, and the system stability and detection efficiency are improved.
Patent Information
- Application Number
- CN202411687596.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-11-25
AI Technical Summary
The existing technology cannot accurately and in real time to detect memory leaks, resulting in memory leaks being unable to be handled in time, affecting system stability and performance.
By analyzing memory data in real time, calculating the average growth rate of a specific time period, comparing it with the average growth rate of a stable time period, comprehensively judging the memory leakage situation and outputting the memory leakage rate.
It realizes accurate, rapid and real-time detection of memory leaks, improves detection efficiency and accuracy, reduces manual intervention, saves manpower and material costs, and improves the stability of the system.
Smart Images

Figure CN119597629A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a memory leak detection method, device, equipment and storage medium. Background Art
[0002] At present, with the rapid development of computer technology, memory leakage has become an important factor affecting the stability and performance of computer systems. Memory leakage refers to the inability of a program to release the memory space it has applied for after applying for memory, which leads to the gradual exhaustion of memory resources and may eventually cause the program to crash or the system to freeze.
[0003] In one prior art, a memory leak detection method often relies on manual analysis or simple threshold judgment.
[0004] The existing technology cannot accurately and real-time discover the memory leak problem, resulting in the memory leak problem cannot be handled in a timely, rapid and accurate manner. Summary of the invention
[0005] The present invention provides a memory leak detection method, device, equipment and storage medium to achieve accurate, rapid and real-time detection of memory leaks, timely discover and handle memory leak problems, and improve detection efficiency and accuracy.
[0006] In a first aspect, in order to solve the above technical problem, the present invention provides a method for detecting a memory leak, comprising:
[0007] Get first memory data;
[0008] Perform a first growth rate judgment according to the first memory data to obtain memory data in a first time period as second memory data;
[0009] Calculating according to the second memory data to obtain a first average growth rate and a second average growth rate;
[0010] Perform a second growth rate judgment according to the first average growth rate and the second average growth rate, and obtain memory data of a second time period as third memory data;
[0011] Calculating according to the third memory data to obtain a third average growth rate;
[0012] Calculating according to the third memory data and the third average growth rate to obtain a first growth amount;
[0013] A memory leak determination is performed based on the first growth amount and the third average growth rate to obtain a memory leak result.
[0014] In an optional implementation manner, performing a first growth rate judgment according to the first memory data to obtain memory data in a first time period as the second memory data includes:
[0015] According to the first memory data, determine whether there is a time period in which the memory growth rate is significantly greater than the normal memory growth rate, and use the time period as the first time period; if so, use the memory data of the first time period as the second memory data; if not, reacquire the first memory data;
[0016] The first memory data includes the memory growth rate, normal memory growth rate and memory growth amount of each memory data in each time period.
[0017] In an optional implementation manner, performing calculation according to the second memory data to obtain the first average growth rate and the second average growth rate includes:
[0018] Calculate the average growth rate of the second memory data and determine it as the first average growth rate; calculate the average growth rate of a stable time period before and closest to the start of the first time period as the second average growth rate;
[0019] The first average growth rate and the second average growth rate are calculated by the following formula:
[0020]
[0021] Wherein, G1 is the first average growth rate, k1 is the preset memory growth coefficient, is the memory growth variance in the first time period, G2 is the second average growth rate, k2 is the preset memory growth coefficient, is the memory growth variance of a stable time period that is closest to and before the first time period;
[0022] in,
[0023] Among them, X i is the memory growth amount in the first time period, is the average value of the memory growth, and n is the number of observations in the first time period;
[0024] in,
[0025] Among them, X j is the memory growth amount in a stable time period that is closest to the first time period, is the average value of the memory growth, and m is the number of observations in a stable time period that is closest to and before the first time period.
[0026] In an optional implementation manner, performing calculation according to the third memory data to obtain a third average growth rate includes:
[0027] Calculate the average growth rate of a stable time period that is closest to the second time period as the third average growth rate;
[0028] The third average growth rate is calculated by the following formula:
[0029]
[0030] Among them, B is the third average growth rate, ΔM i is the memory growth at the i-th time point in the closest stable time period after the second time period, T is the total length of the closest stable time period after the second time period, and z is the number of observations in the closest stable time period after the second time period.
[0031] In an optional implementation manner, the calculating according to the third memory data and the third average growth rate to obtain the growth amount of the third memory data includes:
[0032] Calculate, according to the third memory data, a memory growth amount after the memory growth rate in the second time period decreases, as a first growth amount;
[0033] The first growth amount is calculated by the following formula:
[0034] A2=A1–B*(t2–t3)
[0035] Among them, A2 is the first growth amount, A1 is the memory growth amount in the second time period, B is the third average growth rate, t2 is the second time period, and t3 is the time period after the second time period when the memory growth rate is again significantly higher than the normal memory growth rate.
[0036] In an optional implementation, performing memory leak judgment according to the first growth amount and the second average growth rate data to obtain a memory leak result includes:
[0037] Determine whether there is a memory leak based on the first growth amount and the second average growth rate data: if the first growth amount is a negative number and the first average growth rate is lower than the third average growth rate, there is a memory leak; if the first growth amount is not a negative number, the growth rate of the first memory data fluctuates normally and there is no memory leak.
[0038] In a second aspect, the present invention provides a memory leak detection device, comprising:
[0039] A data acquisition module, used for acquiring first memory data;
[0040] A first growth rate judgment module, used to perform a first growth rate judgment based on the first memory data, and obtain memory data in a first time period as second memory data;
[0041] A first data calculation module, used for performing calculation according to the second memory data to obtain a first average growth rate and a second average growth rate;
[0042] A second growth rate judgment module, configured to perform a second growth rate judgment according to the first average growth rate and the second average growth rate, and obtain memory data of a second time period as third memory data;
[0043] A second data calculation module, used for performing calculation according to the third memory data to obtain a third average growth rate;
[0044] A third data calculation module, used for performing calculation according to the third memory data and the third average growth rate to obtain a first growth amount;
[0045] The memory leak judgment module is used to perform memory leak judgment based on the first growth amount data and the third average growth rate to obtain a memory leak result.
[0046] In a third aspect, the present invention further provides an electronic device comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements a memory leak detection method as described above when executing the computer program.
[0047] In a fourth aspect, the present invention further provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned methods for detecting a memory leak.
[0048] The present invention proposes a method for detecting memory leaks, which intelligently identifies the memory growth trend by analyzing memory data in real time, and accurately calculates the memory growth amount and the leakage amount. The method includes reading and analyzing memory data in real time, calculating the average growth rate in a specific time period, and comparing it with the average growth rate in a stable time period. Through a series of calculation steps, including recording the memory growth amount at key time points, calculating the average memory growth amount in a stable time period, and the memory growth value after the memory growth rate decreases, the present invention can comprehensively judge the memory leakage situation and output the memory leakage rate. In addition, the present invention also provides corresponding detection devices and electronic devices, as well as storage media, to realize the automation and intelligence of the detection method.
[0049] The prior art has many deficiencies in memory leak detection, such as the inability to accurately determine the occurrence time, leakage amount, and cumulative amount of memory leaks, the inability to automatically detect, and the need for a large amount of manual intervention. In view of these deficiencies, the present invention monitors the changes in memory data in real time, obtains first memory data, performs a first growth rate judgment based on the first memory data, obtains second memory data, performs calculations based on the second memory data, obtains a first average growth rate and a second average growth rate, performs a second growth rate judgment based on the first average growth rate and the second average growth rate, obtains third memory data, performs calculations based on the third memory data, obtains a third average growth rate, performs calculations based on the third memory data and the third average growth rate, obtains a first growth amount, performs memory leak judgment based on the first growth amount and the third average growth rate, and obtains a memory leak result. This method not only improves the accuracy of detection, but also reduces manual intervention, and realizes the automation of memory leak detection. By calculating the growth rate and the memory growth amount, and performing a comprehensive judgment based on the actual situation, the present invention can timely discover memory leaks and provide quantitative leakage data, thereby providing strong technical support for system maintenance and optimization.
[0050] Compared with the prior art, the present invention has the following beneficial effects: First, it can monitor and analyze memory data in real time, detect memory leaks in a timely manner, and improve the efficiency and accuracy of memory management. Secondly, by accurately calculating the amount of memory growth and leakage, the present invention provides a quantitative memory leak detection method, so that maintenance personnel can more accurately understand the memory status of the system. In addition, the automated and intelligent detection device of the present invention reduces manual intervention, saves manpower and material costs, and shortens testing time. Finally, when a memory leak is detected, the present invention can send a warning signal to the user, improving the stability of the system and the user experience. In general, the present invention provides an efficient, accurate and automated solution for the detection of memory leaks through its innovative detection method and device. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 It is a flowchart of a method for detecting a memory leak provided by the first embodiment of the present invention;
[0052] Figure 2 It is a schematic diagram of the structure of a memory leak detection device provided by the second embodiment of the present invention. DETAILED DESCRIPTION
[0053] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0054] At present, with the rapid development of computer technology, memory leakage has become an important factor affecting the stability and performance of computer systems. Memory leakage refers to the inability of a program to release the memory space it has applied for after applying for memory, which leads to the gradual exhaustion of memory resources and may eventually cause the program to crash or the system to freeze.
[0055] In one prior art, a memory leak detection method often relies on manual analysis or simple threshold judgment.
[0056] The existing technology cannot accurately and real-time discover the memory leak problem, resulting in the memory leak problem cannot be handled in a timely, rapid and accurate manner.
[0057] In order to solve the above technical problems, refer to Figure 1 The first embodiment of the present invention provides a method for detecting a memory leak, comprising the following steps:
[0058] S11, obtaining first memory data;
[0059] S12, performing a first growth rate judgment based on the first memory data to obtain memory data in a first time period as second memory data;
[0060] S13, performing calculation according to the second memory data to obtain a first average growth rate and a second average growth rate;
[0061] S14, performing a second growth rate judgment according to the first average growth rate and the second average growth rate, and obtaining memory data of a second time period as third memory data;
[0062] S15, performing calculation according to the third memory data to obtain a third average growth rate;
[0063] S16, performing calculation according to the third memory data and the third average growth rate to obtain a first growth amount;
[0064] S17, performing memory leak judgment based on the first growth amount and the third average growth rate to obtain a memory leak result.
[0065] In step S11, first memory data is obtained.
[0066] The first memory data in the step refers to the memory growth rate, normal memory growth rate and memory growth amount in each time period. These first memory data are the basis of the memory leak detection method, and they can reflect the memory usage of the system at different time points. The memory growth rate can indicate the changing trend of memory usage, while the normal memory growth rate and memory growth amount provide a reference benchmark for judging memory leaks.
[0067] It should be noted that the memory growth rate, normal memory growth rate, and memory growth amount in each time period are obtained by monitoring and recording the memory usage of the system during operation. Specifically, this information can be captured by reading the memory usage data provided by the operating system in real time, or by using a dedicated performance monitoring tool. This data includes detailed records of memory allocation, release, and occupancy, as well as memory usage statistics that change over time. By analyzing this data, the memory growth rate and memory growth amount can be calculated, and then the normal memory growth rate can be obtained.
[0068] The use of the first memory data obtained in this step is mainly for subsequent memory leak detection. The first memory data is used as input to facilitate more in-depth analysis and comparison in subsequent steps. For example, by comparing the actual memory growth rate with the normal memory growth rate, possible signs of memory leaks can be identified. In this step, the use of the normal memory growth rate is fundamental, and it provides necessary data support for subsequent growth rate judgment, average growth rate calculation and other steps.
[0069] In step S12, a first growth rate judgment is performed based on the first memory data to obtain memory data in a first time period as second memory data.
[0070] The core of this step is to identify and judge the abnormal growth rate in memory data. The identification of abnormal growth rate is achieved by analyzing the memory usage during the program running, especially whether the memory growth rate is significantly higher than the normal level.
[0071] It should be noted that the first growth rate judgment requires the analysis of first memory data, which includes memory growth rate, normal memory growth rate and memory growth amount in different time periods. By monitoring and recording these data, the changes in memory usage over time are captured. This process usually involves real-time monitoring tools and built-in operating system functions, which can track and record memory usage and provide raw data for subsequent analysis.
[0072] Specifically, to make the first growth rate judgment, it is necessary to determine whether there is a time period in which the memory growth rate is significantly greater than the normal memory growth rate. If there is such a time period, the memory data in this time period will be marked as abnormal and further analyzed as the second memory data. This judgment process is based on the preset normal memory growth rate threshold. By comparing the actual observed growth rate with this threshold, it is determined whether abnormal growth has occurred. This method helps to discover potential memory leak problems in a timely manner, so that corresponding measures can be taken to repair or optimize them.
[0073] In step S13, calculation is performed based on the second memory data to obtain a first average growth rate and a second average growth rate.
[0074] This step is to calculate two average growth rates from the second memory data, which represent the average rates of memory growth in different time periods. The first average growth rate refers to the average growth rate in the first time period of the identified abnormal memory growth rate, while the second average growth rate refers to the average growth rate in a relatively stable period before the abnormal time period. The acquisition of these two growth rates is crucial for subsequent memory leak judgment, because they can help distinguish normal memory usage patterns from potential memory leaks.
[0075] Specifically, the calculation method is implemented by means of statistical analysis. First, for the first time period, that is, the time period with an abnormal memory growth rate, the growth of all memory data in the time period is calculated, and the average of these growth amounts is obtained, combined with the variance of the memory data growth amount, to obtain the first average growth rate. Similarly, for a stable time period before and closest to the first time period, the same method is used to calculate its average growth rate, which is the second average growth rate. The key to obtaining the first average growth rate and the second average growth rate is to correctly identify the stable time period and ensure that the selected time period does reflect the memory growth during normal operation of the system, thereby providing a benchmark for subsequent comparisons.
[0076] The first average growth rate and the second average growth rate are calculated by the following formula:
[0077]
[0078] Wherein, G1 is the first average growth rate, k1 is the preset memory growth coefficient, is the memory growth variance in the first time period, G2 is the second average growth rate, k2 is the preset memory growth coefficient, is the memory growth variance of a stable time period that is closest to and before the first time period;
[0079] in,
[0080] Among them, X i is the memory growth amount in the first time period, is the average value of the memory growth, and n is the number of observations in the first time period;
[0081] in,
[0082] Among them, X j is the memory growth amount in a stable time period that is closest to the first time period, is the average value of the memory growth, and m is the number of observations in a stable time period that is closest to and before the first time period.
[0083] In step S14, a second growth rate judgment is performed based on the first average growth rate and the second average growth rate to obtain memory data of a second time period as third memory data.
[0084] This step is to determine a new time period by analyzing the growth rates of memory data in two time periods, namely the first average growth rate and the second average growth rate. This new time period is the time period with the largest change in memory growth rate in the first time period. Specifically, by analyzing the changes in memory growth rate in the first time period, several time periods with abnormal growth rate changes are determined, and by comparison, the time interval from the fastest to the slowest memory growth rate is found, which is defined as the second time period. The memory data in this time period is defined as the third memory data. The purpose of this step is to further refine the trend of memory changes and provide more accurate data support for subsequent analysis.
[0085] It should be noted that the third memory data mainly relies on calculating the first average growth rate and the second average growth rate, and judging by the relationship between them. Specifically, first, it is necessary to obtain the first average growth rate, which refers to the average growth rate in the time period of the previously determined abnormal memory growth rate, that is, the first time period. Secondly, the second average growth rate refers to the average growth rate in a stable time period that is considered to be relatively stable before the first time period. By comparing the relationship between the two growth rates, the second growth rate can be judged. If the product of the first average growth rate and the second average growth rate is less than zero, it means that the growth rate has changed in direction. At this time, the growth rate needs to be recalculated and the judgment needs to be continued; if the product is equal to zero, the detection is stopped; if the product is greater than zero, it means that the direction of the growth rate is consistent. At this time, it is necessary to analyze the abnormal data in the first time period, and determine the second time period by analyzing the time period with the largest change in the memory growth rate in the first time period. Specifically, by analyzing the change in the memory growth rate in the first time period, several time periods with abnormal growth rate changes are determined, and the time interval from the fastest to the slowest memory growth rate is found by comparison, and the interval is defined as the second time period. The second time period memory data provided by the operating system is read by the computer, and the second time period memory data is defined as the third memory data.
[0086] Optionally, the judgment process of this step is based on mathematical and statistical principles, and abnormal patterns in memory usage are identified by comparing the changing trends of the two growth rates. This method helps to more accurately locate the problem time period during the memory leak detection process and provide key information for subsequent memory leak judgment.
[0087] Among them, the specific method for determining the second growth rate is:
[0088] If a×b<0, recalculate the first average growth rate and the second average growth rate, and continue to determine the second growth rate;
[0089] If a×b=0, stop the detection;
[0090] If a×b>0, then the time period from the fastest growth rate to the slowest growth rate in the first time period is recorded as the second time period, and the memory data of the second time period is used as the third memory data;
[0091] Wherein, a is the first average growth rate, and b is the second average growth rate.
[0092] In step S15, a calculation is performed based on the third memory data to obtain a third average growth rate.
[0093] This step mainly focuses on the change in the growth rate of memory data after the second time period. The third average growth rate is determined by analyzing the memory growth in the stable time period immediately after the second time period to determine the average growth rate in the time period, that is, the third average growth rate.
[0094] It should be noted that the third average growth rate is achieved by calculating the memory growth rate in a stable time period closest to the second time period. This process involves the memory growth at each time point in the time period and calculating the average of these growth amounts. Specifically, it is necessary to determine the total duration and number of observations of the time period, and then use these data to calculate the average growth rate. This calculation process is based on time series analysis methods, which quantifies the trend of memory growth through statistical and mathematical processing.
[0095] Optionally, after the third average growth rate is calculated, it can be directly used to evaluate the stability of memory usage during this period. For example, by observing the size of the third average growth rate, the fluctuation of memory usage during this period can be preliminarily determined. If the third average growth rate remains within a small range, it indicates that the memory usage during this period is relatively stable; conversely, if the third average growth rate is large, it indicates that there may be large memory fluctuations. Therefore, the calculation of the third average growth rate is an important indicator for measuring the memory growth after the second time period. This indicator helps to further analyze the memory usage pattern and provide data support for determining whether there is a memory leak.
[0096] The third average growth rate is calculated by the following formula:
[0097]
[0098] Among them, B is the third average growth rate, ΔM i is the memory growth at the i-th time point in the closest stable time period after the second time period, T is the total length of the closest stable time period after the second time period, and z is the number of observations in the closest stable time period after the second time period.
[0099] In step S16, a calculation is performed based on the third memory data and the third average growth rate to obtain a growth amount of the third memory data.
[0100] This step is to quantitatively analyze the growth of memory data. Specifically, after identifying the time window with abnormal memory growth rate, the growth of memory data in this time period is calculated. The core of quantitative analysis of memory data growth is to accurately determine the actual increase in memory usage under specific conditions through mathematical calculations, thereby providing key data for further memory leak analysis.
[0101] The growth amount of the third memory data involves an in-depth analysis of the third memory data. Specifically, first, it is necessary to determine a stable time period after the second time period and calculate the average growth rate in this time period, that is, the third average growth rate. Then, using this average growth rate and the memory data in a specific time window, the growth amount of the third memory data is calculated by the formula
[0102] It should be noted that the growth amount of the third memory data is to find out the difference between the growth amount and the memory growth pattern when the system is operating normally. In this step, the growth amount of the third memory data is used to compare with the third average growth rate to determine whether the growth of memory in a specific time period exceeds the normal fluctuation range. This method helps to identify memory leaks that may not be discovered by conventional monitoring methods because it provides a quantitative indicator to measure the actual growth of memory usage. Through analysis, potential memory leaks can be located more accurately, so that corresponding optimization measures can be taken.
[0103] The first growth amount is calculated by the following formula:
[0104] A2=A1–B*(t2–t3)
[0105] Among them, A2 is the first growth amount, A1 is the memory growth amount in the second time period, B is the third average growth rate, t2 is the second time period, and t3 is the time period after the second time period when the memory growth rate is again significantly higher than the normal memory growth rate.
[0106] In step S17, a memory leak determination is performed based on the first growth amount and the second average growth rate data to obtain a memory leak result.
[0107] This step is to comprehensively analyze the growth amount and average growth rate of memory data to determine whether there is a memory leak in the system. The core of this step is to determine whether there is an abnormal growth pattern of memory usage, that is, a memory leak, by comparing the first growth amount and the second average growth rate.
[0108] It is worth noting that this step is first based on the first growth amount, the first average growth rate and the third average growth rate, and by calculating and comparing these data, key indicators for memory leak judgment are obtained.
[0109] It should be noted that the memory leak judgment is analyzed using the mathematical relationship between the first growth amount, the first average growth rate and the third average growth rate. Specifically, if the first growth amount is a negative number, and the first average growth rate is lower than the third average growth rate, then it can be determined that there is a memory leak. This judgment is based on the abnormal changes in the memory growth amount and growth rate, indicating that there are problems in the memory allocation and release process. If the first growth amount is not a negative number, it indicates that the growth rate of the memory data is a normal fluctuation and there is no sign of a memory leak.
[0110] In summary, the present invention proposes a method for detecting memory leaks, which intelligently identifies the memory growth trend by analyzing memory data in real time, and accurately calculates the memory growth amount and the leakage amount. The method includes reading and analyzing memory data in real time, calculating the average growth rate in a specific time period, and comparing it with the average growth rate in a stable time period. Through a series of calculation steps, including recording the memory growth amount at key time points, calculating the average memory growth amount in a stable time period, and the memory growth value after the memory growth rate decreases, the present invention can comprehensively judge the memory leakage situation and output the memory leakage rate. In addition, the present invention also provides corresponding detection devices and electronic devices, as well as storage media, to realize the automation and intelligence of the detection method.
[0111] The prior art has many deficiencies in memory leak detection, such as the inability to accurately determine the occurrence time, leakage amount, and cumulative amount of memory leaks, the inability to automatically detect, and the need for a large amount of manual intervention. In view of these deficiencies, the present invention monitors the changes in memory data in real time, obtains first memory data, performs a first growth rate judgment based on the first memory data, obtains second memory data, performs calculations based on the second memory data, obtains a first average growth rate and a second average growth rate, performs a second growth rate judgment based on the first average growth rate and the second average growth rate, obtains third memory data, performs calculations based on the third memory data, obtains a third average growth rate, performs calculations based on the third memory data and the third average growth rate, obtains a first growth amount, performs memory leak judgment based on the first growth amount and the third average growth rate, and obtains a memory leak result. This method not only improves the accuracy of detection, but also reduces manual intervention, and realizes the automation of memory leak detection. By calculating the growth rate and the memory growth amount, and performing a comprehensive judgment based on the actual situation, the present invention can timely discover memory leaks and provide quantitative leakage data, thereby providing strong technical support for system maintenance and optimization.
[0112] Compared with the prior art, the present invention has the following beneficial effects: First, it can monitor and analyze memory data in real time, detect memory leaks in a timely manner, and improve the efficiency and accuracy of memory management. Secondly, by accurately calculating the amount of memory growth and leakage, the present invention provides a quantitative memory leak detection method, so that maintenance personnel can more accurately understand the memory status of the system. In addition, the automated and intelligent detection device of the present invention reduces manual intervention, saves manpower and material costs, and shortens testing time. Finally, when a memory leak is detected, the present invention can send a warning signal to the user, improving the stability of the system and the user experience. In general, the present invention provides an efficient, accurate and automated solution for the detection of memory leaks through its innovative detection method and device.
[0113] Reference Figure 2 A second embodiment of the present invention provides a memory leak detection device, comprising:
[0114] A data acquisition module, used for acquiring first memory data;
[0115] A first growth rate judgment module, used to perform a first growth rate judgment based on the first memory data, and obtain memory data in a first time period as second memory data;
[0116] A first data calculation module, used for performing calculation according to the second memory data to obtain a first average growth rate and a second average growth rate;
[0117] A second growth rate judgment module, configured to perform a second growth rate judgment according to the first average growth rate and the second average growth rate, and obtain memory data of a second time period as third memory data;
[0118] A second data calculation module, used for performing calculation according to the third memory data to obtain a third average growth rate;
[0119] A third data calculation module, used for performing calculation according to the third memory data and the third average growth rate to obtain a first growth amount;
[0120] The memory leak judgment module is used to perform memory leak judgment based on the first growth amount data and the third average growth rate to obtain a memory leak result.
[0121] In an optional implementation manner, performing a first growth rate judgment according to the first memory data to obtain memory data in a first time period as the second memory data includes:
[0122] According to the first memory data, determine whether there is a time period in which the memory growth rate is significantly greater than the normal memory growth rate, and use the time period as the first time period; if so, use the memory data of the first time period as the second memory data; if not, reacquire the first memory data;
[0123] The first memory data includes the memory growth rate, normal memory growth rate and memory growth amount of each memory data in each time period.
[0124] In an optional implementation manner, performing calculation according to the second memory data to obtain the first average growth rate and the second average growth rate includes:
[0125] Calculate the average growth rate of the second memory data and determine it as the first average growth rate; calculate the average growth rate of a stable time period before and closest to the start of the first time period as the second average growth rate;
[0126] The first average growth rate and the second average growth rate are calculated by the following formula:
[0127]
[0128] Wherein, G1 is the first average growth rate, k1 is the preset memory growth coefficient, is the memory growth variance in the first time period, G2 is the second average growth rate, k2 is the preset memory growth coefficient, is the memory growth variance of a stable time period that is closest to and before the first time period;
[0129] in,
[0130] Among them, X i is the memory growth amount in the first time period, is the average value of the memory growth, and n is the number of observations in the first time period;
[0131] in,
[0132] Among them, X j is the memory growth amount in a stable time period that is closest to the first time period, is the average value of the memory growth, and m is the number of observations in a stable time period that is closest to and before the first time period.
[0133] In an optional implementation manner, performing calculation according to the third memory data to obtain a third average growth rate includes:
[0134] Calculate the average growth rate of a stable time period that is closest to the second time period as the third average growth rate;
[0135] The third average growth rate is calculated by the following formula:
[0136]
[0137] Among them, B is the third average growth rate, ΔM i is the memory growth at the i-th time point in the closest stable time period after the second time period, T is the total duration of the closest stable time period after the second time period, and z is the number of observations in the closest stable time period after the second time period.
[0138] In an optional implementation manner, the calculating according to the third memory data and the third average growth rate to obtain the growth amount of the third memory data includes:
[0139] Calculate, according to the third memory data, a memory growth amount after the memory growth rate in the second time period decreases, as a first growth amount;
[0140] The first growth amount is calculated by the following formula:
[0141] A2=A1–B*(t2–t3)
[0142] Among them, A2 is the first growth amount, A1 is the memory growth amount in the second time period, B is the third average growth rate, t2 is the second time period, and t3 is the time period after the second time period when the memory growth rate is again significantly higher than the normal memory growth rate.
[0143] In an optional implementation, performing memory leak judgment according to the first growth amount and the second average growth rate data to obtain a memory leak result includes:
[0144] Determine whether there is a memory leak based on the first growth amount and the second average growth rate data: if the first growth amount is a negative number and the first average growth rate is lower than the third average growth rate, there is a memory leak; if the first growth amount is not a negative number, the growth rate of the first memory data fluctuates normally and there is no memory leak.
[0145] It should be noted that a memory leak detection device provided in an embodiment of the present invention is used to execute all process steps of a memory leak detection method in the above embodiment, and the working principles and beneficial effects of the two correspond one to one, so they will not be described in detail.
[0146] An embodiment of the present invention further provides an electronic device. The electronic device includes: a processor, a memory, and a computer program stored in the memory and executable on the processor, such as a first memory data acquisition program. When the processor executes the computer program, the steps in the above-mentioned memory leak detection method embodiment are implemented, such as Figure 1 Alternatively, when the processor executes the computer program, the functions of the modules / units in the above-mentioned device embodiments are realized, such as the data acquisition module.
[0147] Exemplarily, the computer program may be divided into one or more modules, which are stored in the memory and executed by the processor to implement the present invention. The one or more modules may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the electronic device.
[0148] The electronic device may be a computing device such as a desktop computer, a notebook, a PDA, and a smart tablet. The electronic device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the above components are merely examples of electronic devices and do not constitute a limitation on the electronic device. The electronic device may include more or fewer components than the above components, or may combine certain components, or different components. For example, the electronic device may also include input and output devices, network access devices, buses, etc.
[0149] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device.
[0150] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the electronic device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0151] Wherein, if the module / unit integrated in the electronic device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0152] It should be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the accompanying drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art may understand and implement it without paying any creative effort.
[0153] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.
Claims
1. A memory leak detection method, characterized in that: Executed by a computer, including: Get first memory data; Perform a first growth rate judgment according to the first memory data to obtain memory data in a first time period as second memory data; Calculating according to the second memory data to obtain a first average growth rate and a second average growth rate; Perform a second growth rate judgment according to the first average growth rate and the second average growth rate, and obtain memory data of a second time period as third memory data; Calculating according to the third memory data to obtain a third average growth rate; Calculating according to the third memory data and the third average growth rate to obtain a first growth amount; A memory leak determination is performed based on the first growth amount and the third average growth rate to obtain a memory leak result.
2. A memory leak detection method according to claim 1, characterized in that: The step of performing a first growth rate judgment according to the first memory data to obtain memory data in a first time period as second memory data includes: According to the first memory data, determine whether there is a time period in which the memory growth rate is significantly greater than the normal memory growth rate, and use the time period as the first time period; if so, use the memory data of the first time period as the second memory data; if not, reacquire the first memory data; The first memory data includes the memory growth rate, normal memory growth rate and memory growth amount of each memory data in each time period.
3. A memory leak detection method according to claim 1, characterized in that: The calculating according to the second memory data to obtain the first average growth rate and the second average growth rate includes: Calculate the average growth rate of the second memory data and determine it as the first average growth rate; calculate the average growth rate of a stable time period that is closest to and before the start of the first time period as the second average growth rate; The first average growth rate and the second average growth rate are calculated by the following formula: Wherein, G1 is the first average growth rate, k1 is the preset memory growth coefficient, is the memory growth variance in the first time period, G2 is the second average growth rate, k2 is the preset memory growth coefficient, is the memory growth variance of a stable time period that is closest to and before the first time period; in, Among them, X i is the memory growth amount in the first time period, is the average value of the memory growth, and n is the number of observations in the first time period; in, Among them, X j is the memory growth amount in a stable time period that is closest to the first time period, is the average value of the memory growth, and m is the number of observations in a stable time period that is closest to and before the first time period.
4. A memory leak detection method according to claim 1, characterized in that: The step of performing a second growth rate judgment according to the first average growth rate and the second average growth rate to obtain memory data of a second time period as third memory data includes: According to the first average growth rate and the second average growth rate, multiplying the first average growth rate and the second average growth rate, and determining the relationship between the result and 0; If a×b<0, recalculate the first average growth rate and the second average growth rate, and continue to determine the second growth rate; If a×b=0, stop the detection; If a×b>0, then the time period from the fastest growth rate to the slowest growth rate in the first time period is recorded as the second time period, and the memory data of the second time period is used as the third memory data; Wherein, a is the first average growth rate, and b is the second average growth rate.
5. A memory leak detection method according to claim 1, characterized in that: The step of calculating according to the third memory data to obtain a third average growth rate includes: Calculate the average growth rate of a stable time period that is closest to the second time period as the third average growth rate; The third average growth rate is calculated by the following formula: Among them, is the third average growth rate, ΔM i is the memory growth at the i-th time point in the closest stable time period after the second time period, T is the total length of the closest stable time period after the second time period, and z is the number of observations in the closest stable time period after the second time period.
6. A memory leak detection method according to claim 1, characterized in that: The calculating according to the third memory data and the third average growth rate to obtain the growth amount of the third memory data includes: Calculate, according to the third memory data, a memory growth amount after the memory growth rate in the second time period decreases, as a first growth amount; The first growth amount is calculated by the following formula: A2=A1–B*(t2–t3) Among them, A2 is the first growth amount, A1 is the memory growth amount in the second time period, B is the third average growth rate, t2 is the second time period, and t3 is the time period after the second time period when the memory growth rate is again significantly higher than the normal memory growth rate.
7. A memory leak detection method according to claim 1, characterized in that: The step of performing memory leak judgment according to the first growth amount and the second average growth rate data to obtain a memory leak result includes: Determine whether there is a memory leak based on the first growth amount and the second average growth rate data: if the first growth amount is a negative number and the first average growth rate is lower than the third average growth rate, there is a memory leak; if the first growth amount is not a negative number, the growth rate of the first memory data fluctuates normally and there is no memory leak.
8. A memory leak detection device, characterized in that: include: A data acquisition module, used for acquiring first memory data; A first growth rate judgment module, used to perform a first growth rate judgment based on the first memory data, and obtain memory data in a first time period as second memory data; A first data calculation module, used for performing calculation according to the second memory data to obtain a first average growth rate and a second average growth rate; A second growth rate judgment module, configured to perform a second growth rate judgment according to the first average growth rate and the second average growth rate, and obtain memory data of a second time period as third memory data; A second data calculation module, used for performing calculation according to the third memory data to obtain a third average growth rate; A third data calculation module, used for performing calculation according to the third memory data and the third average growth rate to obtain a first growth amount; The memory leak judgment module is used to perform memory leak judgment based on the first growth amount data and the third average growth rate to obtain a memory leak result.
9. An electronic device, characterized in that: The invention comprises a processor, a memory and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, a memory leak detection method as claimed in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute a memory leak detection method as claimed in any one of claims 1 to 7.
Citation Information
Patent Citations
Memory leak detection method and device and related equipment
CN115828244A
Memory leak detection method, readable medium and electronic equipment
CN116680161A
Memory resource management method and electronic equipment
CN117112192A
Application development method and system based on freeRTOS embedded system and medium
CN117348876A
Method for improving generation of large number of memory fragments in use of head heap under freeRTOS
CN118708502A