A method, apparatus and related equipment for detecting memory leaks

CN115878458BActive Publication Date: 2026-08-14GUANGZHOU WERIDE TECH LTD CO
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-17
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

内存泄露(Memory Leak),是指在程序运行过程中,分配的内存由于某种原因未释放或无法释放,浪费了系统内存,且易导致应用程序运行速度减慢甚至整个系统崩溃等严重后果

Benefits of technology

[0060]经由上述的技术方案可知,本申请首先获取目标时序数据,其中,所述目标时序数据反映了目标程序在预设时长内各时间点上的内存占用情况。然后,判断所述目标时序数据是否单调递增。当判断出所述目标时序数据单调递增时,意味着目标程序所占用的内存持续增多,可以确定所述目标程序存在内存泄露。当判断出所述目标时序数据并非单调递增时,还需要考虑是否属于波动上升的情况。这种情况下,需要进一步获取所述目标时序数据的各峰值点和各谷值点,然后基于各峰值点和各谷值点确定所述目标程序是否存在内存泄露。本申请基于目标程序的内存占用数据,考虑了存在内存泄露多种数据表现形式,将实际场景转化为具体的计算,能够对内存泄露情况进行有效检测。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115878458B_ABST
    Figure CN115878458B_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, and related equipment for detecting memory leaks. The method includes: acquiring target time-series data, which reflects the memory usage of a target program at various time points within a preset duration; determining whether the target time-series data is monotonically increasing; if so, determining that the target program has a memory leak; if not, acquiring the peak and valley points of the target time-series data; and determining whether the target program has a memory leak based on the peak and valley points. This application, based on the memory usage data of the target program, considers various data manifestations of memory leaks, transforming real-world scenarios into specific calculations, and can effectively detect memory leaks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of memory detection technology, and more specifically, to a method, apparatus and related equipment for detecting memory leaks. Background Technology

[0002] Memory leaks are a common problem in software development. A memory leak occurs when allocated memory is not released or cannot be released during program execution, wasting system memory and potentially leading to serious consequences such as slowing down application performance or even causing system crashes. Memory leaks are characterized by their insidious and cumulative nature, making them more difficult to detect than other memory access errors. Determining whether a memory leak exists is a crucial prerequisite for further resolving this problem. Summary of the Invention

[0003] In view of this, this application provides a memory leak detection method, apparatus and related equipment to effectively detect memory leaks.

[0004] To achieve the above objectives, the first aspect of this application provides a memory leak detection method, comprising:

[0005] Obtain target time-series data, which reflects the memory usage of the target program at various time points within a preset duration;

[0006] Determine whether the target time series data is monotonically increasing;

[0007] If so, it is determined that the target program has a memory leak;

[0008] If not, obtain the peak points and valley points of the target time series data;

[0009] The presence of memory leaks in the target program is determined based on each peak and valley point.

[0010] Preferably, the process of obtaining each peak point of the target time series data includes:

[0011] For each data point x(i) in the target time series data:

[0012] Determine whether the data x(i) satisfies the following equation:

[0013] x(i)≥x(i-1) and x(i)>x(i+1)

[0014] Where x(i-1) is the data at the previous time point of data x(i), and x(i+1) is the data at the next time point of data x(i);

[0015] If so, determine the data x(i) as the peak point.

[0016] Preferably, the process of obtaining each valley point of the target time series data includes:

[0017] For each data point x(i) in the target time series data:

[0018] Determine whether the data x(i) satisfies the following equation:

[0019] x(i)≤x(i-1)andx(i) <x(i+1)

[0020] Where x(i-1) is the data at the previous time point of data x(i), and x(i+1) is the data at the next time point of data x(i);

[0021] If so, the data x(i) is determined as the valley point.

[0022] Preferably, the process of determining whether the target program has a memory leak based on each peak point and each valley point includes:

[0023] Determine whether any valley point is not greater than other valley points after the valley point at any given time point;

[0024] if:

[0025] It was determined that the target program had a memory leak;

[0026] If not:

[0027] Arrange the valley values ​​into a valley value sequence according to time order;

[0028] Select target peak points from the peak points, whose time points are after the first time point of the valley value sequence and before the last time point of the valley value sequence, and arrange the target peak points into a peak sequence according to the time order.

[0029] The cumulative increase and cumulative decrease are calculated based on the valley sequence and the peak sequence;

[0030] Based on the cumulative increase and the cumulative decrease, it is determined whether the target program has a memory leak.

[0031] Preferably, the process of calculating the cumulative increase and cumulative decrease based on the trough sequence and the peak sequence includes:

[0032] The cumulative increase Inc is calculated using the following equation:

[0033] Inc = ∑ i [y(p i )-y(vi+1 )]

[0034] The cumulative decrease Dec is calculated using the following equation:

[0035] Dec = ∑ i [y(p i )-y(v i )]

[0036] Where, p i y(p) represents the i-th peak point in the peak sequence. i ) represents the peak point p i The value of v i Let y(v) represent the i-th valley point in the valley value sequence. i ) represents the valley point v i The value;

[0037] The process of determining whether the target program has a memory leak based on the cumulative increase and the cumulative decrease includes:

[0038] If the cumulative increase and the cumulative decrease satisfy the following equation, then the target program is determined to have a memory leak:

[0039]

[0040] Where Inc is the cumulative increase, Dec is the cumulative decrease, k2 is the preset proportional threshold, and N is the number of valley points in the valley sequence.

[0041] Preferably, the process of acquiring the target time series data includes:

[0042] During the execution of the target program, based on the preset sampling interval and preset sampling duration, the memory size occupied by the target program is obtained using the memory mapping command built into the operating system, thereby obtaining the target time series data.

[0043] Preferably, the process of determining whether the target time-series data is monotonically increasing includes:

[0044] For each data point in the target time series data:

[0045] Determine whether the data is not greater than any data at a time point that is after the data.

[0046] If so, determine whether the earliest data x(0) and the latest data x(N) in the target time series data satisfy the following equation:

[0047] x(N)≥k1·x(0)

[0048] Where k1>1 is a preset constant coefficient;

[0049] If so, the target time-series data is determined to be monotonically increasing.

[0050] A second aspect of this application provides a memory leak detection device, comprising:

[0051] The data acquisition unit is used to acquire target time-series data, which reflects the memory usage of the target program at various time points within a preset duration.

[0052] A trend determination unit is used to determine whether the target time series data is monotonically increasing;

[0053] The first determining unit is used to determine that the target program has a memory leak when the trend judging unit determines that the target time series data is monotonically increasing;

[0054] The inflection point acquisition unit is used to acquire each peak point and each valley point of the target time series data when the trend judgment unit determines that the target time series data is not monotonically increasing.

[0055] The second determining unit is used to determine whether the target program has a memory leak based on each peak point and each valley point.

[0056] A third aspect of this application provides a memory leak detection device, comprising: a memory and a processor;

[0057] The memory is used to store programs;

[0058] The processor is used to execute the program to implement the various steps of the memory leak detection method described above.

[0059] A fourth aspect of this application provides a storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the memory leak detection method described above.

[0060] As described in the above technical solution, this application first obtains target time-series data, which reflects the memory usage of the target program at various time points within a preset duration. Then, it determines whether the target time-series data is monotonically increasing. When the target time-series data is determined to be monotonically increasing, it means that the memory occupied by the target program is continuously increasing, indicating a memory leak in the target program. When the target time-series data is determined not to be monotonically increasing, it is also necessary to consider whether it is a fluctuating increase. In this case, it is necessary to further obtain the peak and trough points of the target time-series data, and then determine whether the target program has a memory leak based on the peak and trough points. This application, based on the memory usage data of the target program, considers various data manifestations of memory leaks, transforming the actual scenario into specific calculations, and can effectively detect memory leaks. Attached Figure Description

[0061] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0062] Figure 1 This is a schematic diagram of the memory leak detection method disclosed in the embodiments of this application;

[0063] Figure 2 This example illustrates the case where the target time-series data disclosed in the embodiments of this application is monotonically increasing;

[0064] Figure 3 This example illustrates a case where the target time-series data disclosed in the embodiments of this application exhibits strictly increasing volatility;

[0065] Figure 4 This example illustrates a case where the target time-series data disclosed in the embodiments of this application exhibits non-strict volatility growth;

[0066] Figure 5 This is a schematic diagram of the memory leak detection device disclosed in the embodiments of this application;

[0067] Figure 6 This is a schematic diagram of the memory leak detection device disclosed in an embodiment of this application. Detailed Implementation

[0068] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0069] The memory leak detection method provided in this application is described below. Please refer to the embodiments. Figure 1 The memory leak detection method provided in this application embodiment may include the following steps:

[0070] Step S101: Obtain the target time series data.

[0071] The target time-series data reflects the memory usage of the target program at various points in time within a preset duration. Understandably, the further the target program runs after it starts, the easier it is to detect memory leaks. Therefore, memory usage is typically observed after the target program has run for a sufficiently long period, and the observation period is extended to the preset duration to collect enough data for subsequent evaluation.

[0072] Step S102: Determine whether the target time series data is monotonically increasing. If yes, proceed to step S103; otherwise, proceed to step S104.

[0073] Step S103: Determine that the target program has a memory leak.

[0074] Step S104: Obtain the peak points and valley points of the target time series data.

[0075] Among them, the peak points and valley points appear alternately, together forming the inflection points of the target time series data.

[0076] Step S105: Determine whether there is a memory leak in the target program based on each peak point and each valley point.

[0077] This application first acquires target time-series data, which reflects the memory usage of the target program at various time points within a preset duration. Then, it determines whether the target time-series data is monotonically increasing. If the target time-series data is determined to be monotonically increasing, it means that the memory occupied by the target program is continuously increasing, indicating a memory leak. If the target time-series data is not monotonically increasing, it is necessary to consider whether it is a fluctuating increase. In this case, it is necessary to further acquire the peak and trough points of the target time-series data, and then determine whether the target program has a memory leak based on these peak and trough points. This application, based on the target program's memory usage data, considers various data manifestations of memory leaks, transforming real-world scenarios into specific calculations, and can effectively detect memory leaks.

[0078] In some embodiments of this application, the process of obtaining target time series data in step S101 may include:

[0079] During the execution of the target program, based on the preset sampling interval and preset sampling duration, the memory size occupied by the target program is obtained using the memory mapping command built into the operating system, thereby obtaining the target time series data.

[0080] Here, a data point is formed by the sampling time point and the collected memory size. The target time series data is composed of all data points within the sampling duration. It can be understood that this sampling duration is the total observation time for memory usage, which is equivalent to the preset duration in step S101.

[0081] In some embodiments of this application, step S102, which determines whether the target time-series data is monotonically increasing, may include:

[0082] For each data point in the target time series data:

[0083] S1: Determine if the data is not greater than any data at a time point that is after this data. If yes, proceed to S2; otherwise, proceed to S4.

[0084] S2, determine whether the earliest data x(0) and the latest data x(N) in the target time series data satisfy equation (1). If yes, execute S3; if no, execute S4.

[0085] x(N)≥k1·x(0) (1)

[0086] Where k1>1 is a preset constant coefficient.

[0087] S3, determine that the target time series data is monotonically increasing.

[0088] in, Figure 2The example illustrates the case where the target time series data is monotonically increasing.

[0089] S4, determine that the target time series data is not monotonically increasing.

[0090] In some embodiments of this application, the process of obtaining each peak point of the target time series data in step S104 may include:

[0091] For each data point x(i) in the target time series data:

[0092] S1. Determine whether the data x(i) satisfies equation (2). If yes, execute S2; otherwise, execute S3.

[0093]

[0094] Where x(i-1) is the data at the previous time point of data x(i), and x(i+1) is the data at the next time point of data x(i).

[0095] S2, determine the data x(i) as the peak point.

[0096] S3, determine the data x(i) as a non-peak point.

[0097] In some embodiments of this application, the process of obtaining each valley point of the target time series data in step S104 may include:

[0098] For each data point x(i) in the target time series data:

[0099] S1. Determine whether the data x(i) satisfies equation (3). If yes, execute S2; otherwise, execute S3.

[0100]

[0101] Where x(i-1) is the data at the previous time point of data x(i), and x(i+1) is the data at the next time point of data x(i).

[0102] S2, determine the data x(i) as the valley point.

[0103] S3, determine the data x(i) as a non-valley point.

[0104] In some embodiments of this application, step S105, which determines whether the target program has a memory leak based on each peak point and each valley point, may include:

[0105] S1: Determine whether any valley point is not greater than other valley points after the valley point in time. If yes, proceed to S2; otherwise, proceed to S3.

[0106] Please see Figure 3 If any trough is no greater than any other trough after it, it means that the troughs become higher as time progresses. The memory usage curve formed by the target time-series data shows a fluctuating upward trend, indicating a memory leak in the target program. Please refer to... Figure 4 When a trough point is lower than the trough point before that trough point, it is necessary to further determine whether there is a memory leak in the target program based on the cumulative increase and cumulative decrease.

[0107] S2, It is determined that the target program has a memory leak.

[0108] S3 arranges the valley points into a valley value sequence according to the time order.

[0109] like Figure 4 The target time series data shown can be used to obtain the valley sequence {v1,v2,v3,v4,v5,v6}.

[0110] S4. Select target peak points from the peak points, with time points after the first time point of the valley value sequence and before the last time point of the valley value sequence, and arrange the target peak points into a peak sequence according to time order.

[0111] like Figure 4 The target time series data shown can be used to obtain the peak sequence {p1,p2,p3,p4,p5}.

[0112] S5 calculates the cumulative increase and cumulative decrease based on the valley and peak sequences.

[0113] S6 determines whether the target program has a memory leak based on the cumulative increase and cumulative decrease.

[0114] In some embodiments of this application, the process of calculating the cumulative increase and cumulative decrease based on the valley sequence and the peak sequence in S5 may include:

[0115] S51, the cumulative increase Inc is calculated using equation (4).

[0116] Inc = ∑ i [y(p i )-y(v i+1 (4)

[0117] S52, the cumulative decrease Dec is calculated using equation (5).

[0118] Dec = ∑ i [y(p i )-y(v i (5)

[0119] Where, p i Let y(p) represent the i-th peak point in the peak sequence. i ) represents the peak point p i The value of v i Let y(v) represent the i-th valley point in the valley value sequence. i ) represents the valley point v i The value.

[0120] In some embodiments of this application, the process of determining whether the target program has a memory leak based on the cumulative increase and cumulative decrease in S6 may include:

[0121] Determine whether the cumulative increase magnitude Inc and the cumulative decrease magnitude Dec satisfy equation (6). If so, then the target program is found to have a memory leak.

[0122]

[0123] Where k2 is the preset proportional threshold, and N is the number of valley points in the valley value sequence.

[0124] The memory leak detection device provided in the embodiments of this application is described below. The memory leak detection device described below can be referred to in correspondence with the memory leak detection method described above.

[0125] Please see Figure 5 The memory leak detection device provided in this application embodiment may include:

[0126] Data acquisition unit 21 is used to acquire target time series data, which reflects the memory usage of the target program at each time point within a preset duration.

[0127] Trend judgment unit 22 is used to determine whether the target time series data is monotonically increasing;

[0128] The first determining unit 23 is used to determine that the target program has a memory leak when the trend judging unit determines that the target time series data is monotonically increasing.

[0129] Inflection point acquisition unit 24 is used to acquire each peak point and each valley point of the target time series data when the trend judgment unit determines that the target time series data is not monotonically increasing.

[0130] The second determining unit 25 is used to determine whether the target program has a memory leak based on each peak point and each valley point.

[0131] In some embodiments of this application, the process of the data acquisition unit 21 acquiring the target time series data may include:

[0132] During the execution of the target program, based on the preset sampling interval and preset sampling duration, the memory size occupied by the target program is obtained using the memory mapping command built into the operating system, thereby obtaining the target time series data.

[0133] In some embodiments of this application, the process by which the trend determination unit 22 determines whether the target time series data is monotonically increasing may include:

[0134] For each data point in the target time series data:

[0135] Determine whether the data is not greater than any data at a time point that is after the data.

[0136] If so, determine whether the earliest data x(0) and the latest data x(N) in the target time series data satisfy the following equation:

[0137] x(N)≥k1·x(0)

[0138] Where k1>1 is a preset constant coefficient;

[0139] If so, the target time-series data is determined to be monotonically increasing.

[0140] In some embodiments of this application, the process by which the inflection point acquisition unit 24 acquires each peak point of the target time series data may include:

[0141] For each data point x(i) in the target time series data:

[0142] Determine whether the data x(i) satisfies the following equation:

[0143] x(i)≥x(i-1) and x(i)>x(i+1)

[0144] Where x(i-1) is the data at the previous time point of data x(i), and x(i+1) is the data at the next time point of data x(i);

[0145] If so, determine the data x(i) as the peak point.

[0146] In some embodiments of this application, the process by which the inflection point acquisition unit 24 acquires each valley point of the target time series data may include:

[0147] For each data point x(i) in the target time series data:

[0148] Determine whether the data x(i) satisfies the following equation:

[0149] x(i)≤x(i-1)andx(i) <x(i+1)

[0150] Where x(i-1) is the data at the previous time point of data x(i), and x(i+1) is the data at the next time point of data x(i);

[0151] If so, the data x(i) is determined as the valley point.

[0152] In some embodiments of this application, the process by which the second determining unit 25 determines whether the target program has a memory leak based on each peak point and each valley point may include:

[0153] Determine whether any valley point is not greater than other valley points after the valley point at any given time point;

[0154] if:

[0155] It was determined that the target program had a memory leak;

[0156] If not:

[0157] Arrange the valley values ​​into a valley value sequence according to time order;

[0158] Select target peak points from the peak points, whose time points are after the first time point of the valley value sequence and before the last time point of the valley value sequence, and arrange the target peak points into a peak sequence according to the time order.

[0159] The cumulative increase and cumulative decrease are calculated based on the valley sequence and the peak sequence;

[0160] Based on the cumulative increase and the cumulative decrease, it is determined whether the target program has a memory leak.

[0161] In some embodiments of this application, 5. the method according to claim 4, characterized in that the process of calculating the cumulative increase and cumulative decrease based on the valley sequence and the peak sequence includes:

[0162] The cumulative increase Inc is calculated using the following equation:

[0163] Inc = ∑ i [y(p i )-y(v i+1 )]

[0164] The cumulative decrease Dec is calculated using the following equation:

[0165] Dec = ∑ i [y(p i )-y(v i )]

[0166] Where, p iy(p) represents the i-th peak point in the peak sequence. i ) represents the peak point p i The value of v i Let y(v) represent the i-th valley point in the valley value sequence. i ) represents the valley point v i The value;

[0167] The process of determining whether the target program has a memory leak based on the cumulative increase and the cumulative decrease includes:

[0168] If the cumulative increase and the cumulative decrease satisfy the following equation, then the target program is determined to have a memory leak:

[0169]

[0170] Where Inc is the cumulative increase, Dec is the cumulative decrease, k2 is the preset proportional threshold, and N is the number of valley points in the valley sequence.

[0171] The memory leak detection device provided in this application embodiment can be applied to memory leak detection equipment, such as computers. Optionally, Figure 6 The hardware structure block diagram of the memory leak detection device is shown below. Figure 6 The hardware structure of a memory leak detection device may include: at least one processor 31, at least one communication interface 32, at least one memory 33, and at least one communication bus 34.

[0172] In this embodiment, the number of processor 31, communication interface 32, memory 33 and communication bus 34 is at least one, and processor 31, communication interface 32 and memory 33 communicate with each other through communication bus 34;

[0173] The processor 31 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.

[0174] The memory 33 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device;

[0175] The memory 33 stores a program, and the processor 31 can call the program stored in the memory 33. The program is used for:

[0176] Obtain target time-series data, which reflects the memory usage of the target program at various time points within a preset duration;

[0177] Determine whether the target time series data is monotonically increasing;

[0178] If so, it is determined that the target program has a memory leak;

[0179] If not, obtain the peak points and valley points of the target time series data;

[0180] The presence of memory leaks in the target program is determined based on each peak and valley point.

[0181] Optionally, the refined and extended functions of the program can be found in the description above.

[0182] This application embodiment also provides a storage medium that can store a program suitable for execution by a processor, the program being used for:

[0183] Obtain target time-series data, which reflects the memory usage of the target program at various time points within a preset duration;

[0184] Determine whether the target time series data is monotonically increasing;

[0185] If so, it is determined that the target program has a memory leak;

[0186] If not, obtain the peak points and valley points of the target time series data;

[0187] The presence of memory leaks in the target program is determined based on each peak and valley point.

[0188] Optionally, the refined and extended functions of the program can be found in the description above.

[0189] In summary:

[0190] This application first acquires target time-series data, which reflects the memory usage of the target program at various time points within a preset duration. Then, it determines whether the target time-series data is monotonically increasing. If the target time-series data is determined to be monotonically increasing, it means that the memory occupied by the target program is continuously increasing, indicating a memory leak. If the target time-series data is not monotonically increasing, it is necessary to consider whether it is a fluctuating increase. In this case, it is necessary to further acquire the peak and trough points of the target time-series data, and then determine whether the target program has a memory leak based on these peak and trough points. This application, based on the target program's memory usage data, considers various data manifestations of memory leaks, transforming real-world scenarios into specific calculations, and can effectively detect memory leaks.

[0191] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0192] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.

[0193] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for detecting memory leaks, characterized in that, include: Obtain target time-series data, which reflects the memory usage of the target program at various time points within a preset duration; Determining whether the target time series data is monotonically increasing specifically includes: for each data point in the target time series data: determining whether the data point is not greater than any data point whose time point is after the data point; if so, determining the earliest data point in the target time series data. Data with the latest time point Does it satisfy the following equation: ,in, It is a preset constant coefficient; if so, the target time series data is determined to be monotonically increasing. If so, it is determined that the target program has a memory leak; If not, obtain the peak points and valley points of the target time series data; Determining whether the target program has a memory leak based on each of the peak points and valley points specifically includes: determining whether any valley point is not greater than other valley points after the valley point; if yes: determining that the target program has a memory leak; if no: arranging the valley points into a valley sequence according to time order; selecting target peak points from the peak points whose time points are after the first time point of the valley sequence and before the last time point of the valley sequence, and arranging the target peak points into a peak sequence according to time order; and calculating the cumulative increase using the following equation. : The cumulative decrease can be calculated using the following equation. : ,in, Indicates the first peak in the peak sequence One peak point, Indicates peak point The value, Represents the first valley value in the valley value sequence. A valley value point, Indicates the valley point The numerical values; if the cumulative increase and the cumulative decrease satisfy the following equation, then it is determined that the target program has a memory leak: , in, The cumulative increase is... The cumulative decrease is... The preset ratio threshold, The number of valley points in the valley value sequence.

2. The method according to claim 1, characterized in that, The process of obtaining each peak point of the target time series data includes: For each data point in the target time series data : Judge data Does it satisfy the following equation: in, For data Data from the previous point in time, For data Data at the next point in time; If so, the data This was identified as the peak point.

3. The method according to claim 1, characterized in that, The process of obtaining each valley point of the target time series data includes: For each data point in the target time series data : Judge data Does it satisfy the following equation: in, For data Data from the previous point in time, For data Data at the next point in time; If so, the data It was identified as a valley point.

4. The method according to claim 1, characterized in that, The process of acquiring target time series data includes: During the execution of the target program, based on the preset sampling interval and preset sampling duration, the memory size occupied by the target program is obtained using the memory mapping command built into the operating system, thereby obtaining the target time series data.

5. A memory leak detection device, characterized in that, include: The data acquisition unit is used to acquire target time-series data, which reflects the memory usage of the target program at various time points within a preset duration. The trend determination unit is used to determine whether the target time series data is monotonically increasing. Specifically, it includes: for each data point in the target time series data: determining whether the data point is not greater than any data point after the data point; if so, determining the earliest data point in the target time series data. Data with the latest time point Does it satisfy the following equation: ,in, It is a preset constant coefficient; if so, the target time series data is determined to be monotonically increasing. The first determining unit is used to determine that the target program has a memory leak when the trend judging unit determines that the target time series data is monotonically increasing. The inflection point acquisition unit is used to acquire each peak point and each valley point of the target time series data when the trend judgment unit determines that the target time series data is not monotonically increasing. The second determining unit is used to determine whether the target program has a memory leak based on each of the peak points and each of the valley points. Specifically, it includes: determining whether any valley point is not greater than other valley points after the valley point in time; if yes: determining that the target program has a memory leak; if no: arranging the valley points into a valley sequence in chronological order; selecting target peak points from the peak points whose time points are after the first time point of the valley sequence and before the last time point of the valley sequence, and arranging the target peak points into a peak sequence in chronological order; and calculating the cumulative increase using the following equation. : The cumulative decrease can be calculated using the following equation. : ,in, Indicates the first peak in the peak sequence One peak point, Indicates peak point The value, Represents the first valley value in the valley value sequence. A valley value point, Indicates the valley point The numerical values; if the cumulative increase and the cumulative decrease satisfy the following equation, then it is determined that the target program has a memory leak: , in, The cumulative increase is... The cumulative decrease is... The preset ratio threshold, The number of valley points in the valley value sequence.

6. A memory leak detection device, characterized in that, include: Memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the memory leak detection method as described in any one of claims 1 to 4.

7. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements each step of the memory leak detection method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Memory leak detection method, device and equipment

    CN111240954A

  • Software aging detection method and device and computer readable storage medium

    CN111400199A