Memory leak detection method and device and computer readable storage medium

By acquiring process memory information for preprocessing and decomposition, and combining it with a prediction model to determine memory leak results, the problem of untimely detection and high false detection rate in existing technologies is solved, realizing real-time detection and early warning of memory leaks and improving system stability.

CN120973653APending Publication Date: 2025-11-18SHENZHEN TCL NEW-TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511057991.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-29
Publication Date
2025-11-18

AI Technical Summary

Technical Problem

Existing memory leak detection methods are not timely and have a high false detection rate, making it difficult to provide early warnings before memory leaks cause serious consequences.

Method used

By acquiring process memory information, performing preprocessing and decomposition, initial trend terms and residual terms are obtained. Memory prediction is then performed in conjunction with a prediction model, and dynamic thresholds are used to determine memory leak results, enabling real-time detection.

Benefits of technology

It improves the timeliness of memory leak detection, enabling early warnings before memory leaks occur, reducing the risk of system lag and crashes, and minimizing losses from failures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120973653A_ABST
    Figure CN120973653A_ABST
Patent Text Reader

Abstract

The invention discloses a memory leak detection method and device and a computer readable storage medium. The method comprises the following steps: acquiring process memory information; predicting based on the process memory information to obtain a memory predicted value; and determining a memory leak result based on the memory predicted value. By adopting the method provided by the invention, early warning can be performed before serious consequences are caused by memory leak, and the timeliness of memory leak detection is improved.
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, specifically to a memory leak detection method, apparatus, and computer-readable storage medium. Background Technology

[0002] With the rapid development of information technology, the scale and complexity of software systems are constantly increasing, and memory leaks pose a serious threat to system performance and stability. Therefore, it is necessary to study memory leak detection methods.

[0003] There are several current methods for detecting memory leaks. One method involves loading a pre-defined memory monitoring dynamic link library when the process under test starts to collect memory allocation information from the start to the end of the process, thereby monitoring for memory leaks. Another method monitors the application's user interface operation information and system memory usage. When memory usage exceeds a threshold, a memory leak warning is issued, and specific operational scenarios are provided to help developers quickly locate the problem. However, traditional memory leak detection methods often face challenges such as untimely detection and a high false positive rate. Summary of the Invention

[0004] This application provides a memory leak detection method, apparatus, and computer-readable storage medium, which improves the timeliness of memory leak detection.

[0005] The technical solution adopted by this invention to solve the problem is as follows:

[0006] In a first aspect, embodiments of this application provide a memory leak detection method, comprising: acquiring process memory information; making predictions based on the process memory information to obtain a memory prediction value; and determining a memory leak result based on the memory prediction value.

[0007] In some embodiments, the step of making predictions based on the process memory information to obtain memory prediction values ​​includes: preprocessing the process memory information to obtain target memory time-series data; decomposing the target memory time-series data to obtain an initial trend term and an initial residual term; and making predictions based on the initial trend term and the initial residual term to obtain memory prediction values.

[0008] In some embodiments, the preprocessing of the process memory information to obtain target memory timing data includes: grouping and sorting the process memory information to obtain initial memory timing data; obtaining the maximum and minimum memory timing values ​​in the initial memory timing data; and standardizing the initial memory timing data based on the maximum and minimum memory timing values ​​to obtain the target memory timing data.

[0009] In some embodiments, the step of decomposing the target memory time-series data to obtain an initial trend term and an initial residual term includes: calculating a first moving average based on the target memory time-series data; calculating a second moving average based on the first moving average; calculating the initial trend term based on the first moving average and the second moving average; and calculating the initial residual term based on the target memory time-series data and the initial trend term.

[0010] In some embodiments, the step of predicting based on the initial trend term and the initial residual term to obtain a memory prediction value includes: predicting based on the initial trend term to obtain a prediction trend term; predicting based on the initial residual term to obtain a prediction residual term; and fusing the prediction trend term and the prediction residual term to obtain the memory prediction value.

[0011] In some embodiments, the step of predicting based on the initial trend term to obtain the predicted trend term includes: correcting the initial trend term based on historical trend terms and random error terms to obtain the predicted trend term;

[0012] The step of fusing the predicted trend term and the predicted residual term to obtain the memory predicted value includes: calculating the variance of the predicted trend term and the variance of the predicted residual term to obtain dynamic weights; and performing weighted calculation on the predicted trend term and the predicted residual term based on the dynamic weights to obtain the memory predicted value.

[0013] In some embodiments, the predicted residual term is obtained by modeling the initial residual term using a first processing model, which includes an input module, a state update module, and an output module. The input module is configured to receive the prediction result at the current time step and the state information at the previous time step. The output module is connected to the input module, and the output module is connected to the input module. The input module is configured to perform calculations on the prediction result at the current time step and the state information at the previous time step. The state update module is configured to perform calculations on the feature representation output by the input module and the memory information at the previous time step to obtain the memory information at the current time step. The output module is configured to perform calculations on the prediction result at the current time step, the state information at the previous time step, and the memory information at the current time step to obtain the state information at the current time step.

[0014] In some embodiments, determining the memory leak result based on the memory prediction value includes: obtaining the historical mean memory usage and the historical standard deviation of memory usage; calculating a dynamic threshold based on the historical mean memory usage and the historical standard deviation of memory usage; and determining the memory leak result based on the memory prediction value and the dynamic threshold.

[0015] Secondly, embodiments of this application provide a memory leak detection device, comprising: an acquisition module for acquiring process memory information; a prediction module for making a prediction based on the process memory information to obtain a memory prediction value; and a determination module for determining a memory leak result based on the memory prediction value.

[0016] Thirdly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, the computer program being loaded by a processor to perform the steps in the memory leak detection method described above.

[0017] The beneficial effects of this application are as follows: By acquiring process memory information, predicting memory values ​​based on this information, and then determining memory leak results based on these predicted values, memory leaks can be detected. Compared to traditional post-event analysis (such as checking logs after a program crash), by acquiring memory information in real time and predicting trends, early warnings can be given before memory leaks cause serious consequences (such as system lag or crashes), thus improving the timeliness of memory leak detection. Attached Figure Description

[0018] To more clearly illustrate the technical solutions in the embodiments of the present invention 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 some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 This is a schematic flowchart of an embodiment of the memory leak detection method provided in this application;

[0020] Figure 2 This is a schematic flowchart of a specific embodiment of step S2 provided in this application;

[0021] Figure 3 This is a schematic flowchart of a specific embodiment of step S23 provided in this application;

[0022] Figure 4 This is a schematic flowchart of a specific embodiment of step S3 provided in this application;

[0023] Figure 5This is a schematic diagram of one embodiment of the memory leak detection device provided in this application.

[0024] Figure 6 This is a schematic diagram of an embodiment of the computer device provided in this application. Detailed Implementation

[0025] 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.

[0026] In the description of this application, the terms "first," "second," "third," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first," "second," "third," etc., may explicitly or implicitly include one or more features.

[0027] In this application, the term "exemplary" is used to mean "used as an example, illustration, or description." Any embodiment described as "exemplary" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use this application. Details are set forth in the following description for purposes of explanation. It should be understood that those skilled in the art will recognize that this application can be made without using these specific details. In other instances, well-known structures and processes are not described in detail to avoid obscuring the description of this application with unnecessary detail. Therefore, this application is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.

[0028] It should be noted that since the method in this application embodiment is executed in a computer device, the processing objects of each computer device exist in the form of data or information, such as time, which is essentially time information. It is understood that if size, quantity, position, etc. are mentioned in subsequent embodiments, they are all corresponding data that exist so that the computer device can process them. Specific details will not be elaborated here.

[0029] Please see Figure 1 , Figure 1 This is a schematic flowchart of an embodiment of the memory leak detection method provided in this application. The memory leak detection method may include the following steps S1 to S3, as detailed below:

[0030] Step S1: Obtain process memory information.

[0031] In this embodiment, process memory information is a data set describing the memory occupied by a running process on a terminal device and its related environment. Process memory information may include the PSS (Proportional Set Size) memory value; it may also include device and time information related to the process's operation, such as device serial number, model, system version, process name, process version, and timestamps indicating when the data was generated. This information can be collected and stored through data tracking to provide basic data for process memory status analysis and prediction in memory leak detection.

[0032] Among them, PSS memory value is a metric for measuring memory usage. By tracking the trend of PSS memory value changes (e.g., whether it continues to increase), abnormal memory consumption can be directly determined. Device serial number is a unique identifier for the terminal device, used to distinguish different physical devices. Model number is the device's model number, reflecting its hardware configuration (e.g., memory capacity, CPU performance). System version is the version of the device's operating system, reflecting the underlying memory management mechanism. Process name is the identifier name of a running process, used to distinguish different applications or services. Process version is the application version number corresponding to the process, reflecting the program's code iteration status. Timestamp records the specific time when memory data was generated, reflecting the time dimension information of memory changes.

[0033] In this embodiment, the terminal device collects and reports process memory information every preset time interval. The preset time interval can be adjusted according to actual conditions. For example, IoT (Internet of Things) devices have strictly limited memory resources and low tolerance for memory leaks, so the preset time interval can be appropriately shortened. At the same time, microservice memory resources can be dynamically allocated, so the reporting frequency can be appropriately reduced to adapt to different devices.

[0034] Step S2: Make a prediction based on process memory information to obtain the memory prediction value.

[0035] Among them, the memory prediction value is the memory usage value obtained by analyzing memory information (such as PSS memory value).

[0036] In some embodiments, such as Figure 2 As shown, step S2, which involves making a prediction based on process memory information to obtain a memory prediction value, may include steps S21 to S23, as detailed below:

[0037] Step S21: Preprocess the process memory information to obtain the target memory timing data.

[0038] In this embodiment of the application, the target memory timing data is timing data obtained by preprocessing the process memory information. By preprocessing the process memory information to remove noise and other noise, the accuracy of the data is improved.

[0039] In some embodiments, the step of preprocessing process memory information to obtain target memory timing data may include: grouping and sorting the process memory information to obtain initial memory timing data; obtaining the maximum and minimum memory timing values ​​in the initial memory timing data; and standardizing the initial memory timing data based on the maximum and minimum memory timing values ​​to obtain target memory timing data.

[0040] Initial memory timing data refers to the memory data sequence formed after grouping and sorting process memory information. The maximum memory timing value is the largest recorded memory value (such as the PSS value) in the initial memory timing data; it reflects the highest level of memory usage achieved by the process corresponding to this timing data under a specific scenario. The minimum memory timing value is the smallest recorded memory value (such as the PSS value) in the initial memory timing data; it reflects the lowest level of memory usage achieved by the process corresponding to this timing data under a specific scenario.

[0041] In some embodiments, the step of grouping and sorting process memory information to obtain initial memory timing data may include: verifying and compressing the process memory information to obtain raw memory information and saving the raw memory information; cleaning the raw memory information; grouping the cleaned raw memory information to obtain multiple sets of memory data; and sorting each set of memory data according to time order to obtain initial memory timing data.

[0042] In this embodiment of the application, the original memory information refers to the information obtained after verifying and compressing the process memory information.

[0043] Specifically, the raw memory information is validated to verify the completeness and accuracy of the collected information (such as PSS values, device information, timestamps, etc.), for example, checking for missing fields and whether timestamps are consecutive. Lightweight compression (such as JSON serialization or binary encoding) is then applied to the validated data to reduce storage size while preserving the original data characteristics. Next, the raw memory information is cleaned to remove outliers and noise. Then, the cleaned raw memory information is grouped according to specific dimensions (such as the same process, the same device, the same system version, etc.) and sorted by timestamp from smallest to largest, forming initial memory time-series data arranged in chronological order.

[0044] In some embodiments, the method for standardizing initial memory timing data based on the maximum and minimum memory timing values ​​to obtain target memory timing data specifically includes: calculating the initial memory timing data and the maximum memory timing value to obtain a first difference; calculating the maximum and minimum memory timing values ​​to obtain a second difference; and calculating the target memory timing data based on the first and second differences.

[0045] Optionally, the standardization process for the target memory time-series data can be represented as:

[0046]

[0047] In formula (1), X(t) represents the initial memory timing data, X max X represents the maximum memory timing value. min X represents the minimum memory timing value. norm (t) represents the target memory timing data.

[0048] Step S22: Decompose the target memory time-series data to obtain the initial trend term and the initial residual term.

[0049] In some embodiments, step S22, decomposing the target memory time-series data to obtain an initial trend term and an initial residual term, may include: calculating a first moving average based on the target memory time-series data; calculating a second moving average based on the first moving average; calculating an initial trend term based on the first and second moving averages; and calculating an initial residual term based on the target memory time-series data and the initial trend term.

[0050] In some embodiments, the method for calculating a moving average based on target memory timing data specifically includes: calculating a dynamic window; and calculating a moving average based on the dynamic window and the target memory timing data.

[0051] Optionally, the method for calculating a single moving average can be expressed as follows:

[0052]

[0053] In formula (2), W t This represents the dynamic window, where β is the linear regression slope of the data in the nearest minimum constraint window (e.g., 30 data points), and ∈ represents the local minimum (e.g., 10). -6 ), used to prevent division by zero. min It is the minimum constraint window (e.g., 30 data points), W max It is the maximum constraint window (e.g., 120 data points), while clip means that the constraint will be between the minimum and maximum constraint windows.

[0054] In formula (3), MA1(t) is the first-order moving average, X norm (i) represents the target memory timing data. Formula (3) is a one-time moving average calculation for time point t, used to smooth noise.

[0055] In some embodiments, the method for calculating a secondary moving average based on a primary moving average specifically includes: calculating a secondary moving average based on a dynamic window and a primary moving average.

[0056] Alternatively, the method for calculating the second moving average can be expressed as follows:

[0057]

[0058] In formula (4), MA2(t) is the second moving average. t This represents a dynamic window. MA1(i) is the first-order moving average. Formula (4) is the second-order moving average calculated at time point t, used to extract trends.

[0059] Alternatively, the initial trend term can be calculated as follows:

[0060] T(t-1)=2*MA1(t-1)-MA2(t-1) (Formula 5)

[0061] In formula (5), T(t-1) is the initial trend term (i.e. the current trend term), MA1(t-1) is the (current) quadratic moving average at time point t-1, and MA2(t-1) is the (current) quadratic moving average at time point t-1. Formula (5) is the calculation of the initial trend term, used to eliminate lag and reflect the growth trend of memory.

[0062] Alternatively, the initial residual term can be calculated as follows:

[0063] R(t-1)=X norn (t-1)-T(t-1) (Formula 6)

[0064] In formula (6), R(t-1) is the initial residual term (i.e., the current residual term), X norn (t-1) represents the (current) target memory time series data at time point t-1, and T(t-1) represents the initial trend term (i.e., the current trend term). Formula (6) is used to calculate the initial residual term, which is used to separate the residual term and includes periodic fluctuations, noise, and sudden leakage signals.

[0065] Step S23: Make predictions based on the initial trend term and the initial residual term to obtain the memory prediction value.

[0066] The memory prediction value is obtained by predicting the initial trend term and the initial residual term. It can comprehensively reflect the future memory usage. This value includes both the overall trend of memory change and the impact of short-term fluctuations, and can more accurately predict memory changes.

[0067] In some embodiments, such as Figure 3 As shown, step S23, predicting based on the initial trend term and the initial residual term to obtain the memory prediction value, may include steps S231 to S233, as detailed below:

[0068] Step S231: Make a prediction based on the initial trend term to obtain the predicted trend term.

[0069] In this embodiment, the predicted trend term is obtained from the initial trend term and can reflect the long-term change direction and rate of memory usage, providing a basis for trend judgment for memory leak detection.

[0070] In some embodiments, step S231, predicting based on the initial trend term to obtain the predicted trend term, may include: correcting the initial trend term based on the historical trend term and the random error term to obtain the predicted trend term.

[0071] Specifically, based on the historical trend term and the random error term, the initial trend term is corrected to obtain the predicted trend term, which can be expressed as:

[0072]

[0073] In formula (7), T t This represents the predicted trend term, B is the shift operator, and BT is the forward operator. t =T t-1 B 2 T t =T t-2 ...(and so on), where T t-1 As the initial trend term, T t-i (t≥i≥2) represents the historical trend term. p is the autoregression order, which can be determined by the cutoff position of the partial autocorrelation plot (PACF). d is the difference order, determined by the minimum difference order that makes the series stationary, as determined by the ADF test. q is the moving average order, determined by the cutoff position of the autocorrelation plot (ACF). θ represents the model coefficients (e.g., the ARIMA model), ∈ t This is the random error term.

[0074] In some embodiments, the autoregressive coefficient p, difference order d, and moving average order q in formula (7) are selected using the AIC / BIC criterion to minimize the model loss (p, d, q).

[0075] For example, when the combination (p, d, q) is set to (1, 1, 1), the predicted trend term T can be obtained from formula (7). t for:

[0076]

[0077] In formula (8), T t To predict the trend term, T t-1 As the initial trend term, T t-i (t≥i≥2) represents the historical trend term. θ is the model coefficient, ∈ t This is the random error term.

[0078] Step S232: Make a prediction based on the initial residual term to obtain the predicted residual term.

[0079] In some embodiments, the predicted residual term is obtained by modeling the initial residual term using a first processing model, which includes an input module, a state update module, and an output module. The input module is configured to receive the prediction result at the current time step and the state information at the previous time step. The output module is connected to the input module, and the output module is connected to the input module. The input module is configured to perform calculations on the prediction result at the current time step and the state information at the previous time step. The state update module is configured to perform calculations on the feature representation output by the input module and the memory information at the previous time step to obtain the memory information at the current time step. The output module is configured to perform calculations on the prediction result at the current time step, the state information at the previous time step, and the memory information at the current time step to obtain the state information at the current time step.

[0080] In some embodiments, the first processing model may be built based on an LSTM (Long Short-Term Memory) network.

[0081] In some embodiments, the method for the input module to calculate and process the prediction result of the current time step and the state information of the previous time step specifically includes: concatenating the prediction result of the current time step and the state information of the previous time step to obtain concatenated feature information; calculating and processing the concatenated feature information, the first weight information and the first bias information to obtain the feature information of the current time step; and calculating and processing the concatenated feature information, the second weight information and the second bias information to obtain the output ratio of the current time step.

[0082] Optionally, the feature information and output ratio of the current time step can be calculated using the following formula:

[0083] i t =σ(W i *[ht-1 ,x t ]+b i ) (Formula 9)

[0084]

[0085] In formulas (9) and (10), i t This indicates the output ratio at the current time step. h represents the feature information of the current time step. t-1 x represents the state information of the previous time step. t This represents the prediction result at the current time step, where σ represents the sigmoid function, and W... i This represents the first weight information, b. i W represents the first bias information. C This represents the second weighting information, b. C Indicates the second bias information, [h t-1 ,x t ] represents the state information h of the previous time step. t-1 The prediction result x at the current time step t Perform splicing processing.

[0086] In some embodiments, the step of the state update module calculating and processing the feature representation output by the input module and the memory information of the previous time step to obtain the memory information of the current time step specifically includes: calculating and processing the concatenated feature information, the third weight information, and the third bias information to obtain a first ratio value; and performing weighted calculation processing on the memory information of the previous time step and the feature information of the current time step output by the input module based on the first ratio value and the output ratio of the current time step to obtain the memory information of the current time step.

[0087] Optionally, the state update module calculates and processes the feature representation output by the input module and the memory information of the previous time step to obtain the memory information of the current time step, which can be represented as:

[0088]

[0089] f t =σ(W f *[h t-1 ,x t ]+b f )(Formula 12)

[0090] In formulas (11) and (12), C t This represents the memory information at the current time step. (C) t-1 This represents the memory information from the previous time step. t This indicates the output ratio at the current time step. Represents the feature information of the current time step, [h t-1 ,x t ] represents the splicing feature information, W f This represents the third weight information, b f This represents the third bias information, f t Represents the first proportional value, σ represents the sigmoid function, and h t-1 The state information of the previous time step, x t The prediction result at the current time step. W f and b f It is a trainable parameter, which is usually automatically updated during model training using the backpropagation algorithm.

[0091] In some embodiments, the output module performs calculations on the prediction result of the current time step, the state information of the previous time step, and the memory information of the current time step to obtain the state information of the current time step. Specifically, this includes: performing calculations on the splicing feature information, the fourth weight information, and the fourth bias information to obtain the long-term information of the current time step; and performing calculations on the long-term information of the current time step and the memory information of the current time step to obtain the state information of the current time step.

[0092] Optionally, the output module performs calculations on the prediction result of the current time step, the state information of the previous time step, and the memory information of the current time step to obtain the state information of the current time step, which can be represented as:

[0093] o t =σ(W o *[h t-1 ,x t ]+b o )(Formula 13)

[0094] h t =o t ⊙tanh(C t )(Formula 14)

[0095] In formulas (13) and (14), o t h represents long-term information at the current time step. t This represents the state information at the current time step, where σ represents the sigmoid function, and W... o It is the fourth weighting information, h t-1 x represents the state information of the previous time step. t This represents the prediction result at the current time step, [h] t-1 ,x t ] indicates splicing feature information, b o It is the fourth bias information, C t It represents the memory information of the current time step.

[0096] Step S233: The predicted trend term and the predicted residual term are fused to obtain the memory predicted value.

[0097] In this embodiment, the memory prediction value is obtained by fusing the prediction trend term and the prediction residual term. The memory prediction value retains both the long-term trend characteristics of memory usage (prediction trend term) and the impact of short-term random fluctuations (prediction residual term), which can more comprehensively reflect the overall trend of future memory changes and provide a more accurate basis for subsequent anomaly detection, resource scheduling, etc.

[0098] In some embodiments, step S233, fusing the predicted trend term and the predicted residual term to obtain the memory predicted value, may include: calculating the variance of the predicted trend term and the variance of the predicted residual term to obtain dynamic weights; and performing weighted calculation on the predicted trend term and the predicted residual term based on the dynamic weights to obtain the memory predicted value.

[0099] Optionally, the method for calculating and processing the variance of the predicted trend term and the variance of the predicted residual term to obtain the dynamic weights can be expressed as follows:

[0100]

[0101] In formula (15), α represents the dynamic weight. This represents the variance of the predicted trend term. This represents the variance of the predicted residual term, and ∈ indicates the minimum value (10). -6 ), used to prevent division by zero.

[0102] Optionally, the method of obtaining the in-memory predicted value by weighting the predicted trend term and the predicted residual term based on dynamic weights can be expressed as follows:

[0103]

[0104] In formula (16), Let α represent the memory-predicted value, α represent the dynamic weight, T(t) represent the prediction trend term, and R(t) represent the prediction residual term.

[0105] Step S3: Determine the memory leak result based on the memory prediction value.

[0106] The memory leak result is a conclusion drawn from memory prediction values ​​and is used to determine whether a process has a memory leak. Determining the memory leak result through memory prediction values ​​combines the foresight of the prediction values ​​with trend analysis to distinguish between normal fluctuations and leaky growth, thereby improving the accuracy of memory leak detection.

[0107] In some embodiments, such as Figure 4As shown, step S3, determining the memory leak result based on the memory prediction value, may include steps S31 to S33, as detailed below:

[0108] Step S31: Obtain the historical average memory usage and the historical standard deviation of memory usage.

[0109] In this embodiment, the historical average memory usage refers to the average memory usage of a process or system over a past period (such as a specific period or under the same historical business scenario). For example, the average hourly memory usage of an application over the past 7 days.

[0110] Historical memory standard deviation is a metric that measures the dispersion of historical memory usage. A larger historical memory standard deviation indicates more drastic fluctuations in historical memory usage; conversely, a smaller standard deviation indicates more stable memory usage. For example, if a process's memory usage fluctuates within a small range around the mean, its standard deviation will be smaller; if it experiences frequent and significant fluctuations, the standard deviation will be larger.

[0111] Step S32: Calculate the dynamic threshold based on the historical average memory usage and the historical standard deviation of memory usage.

[0112] In some embodiments, the sum of the historical memory usage mean and the historical memory standard deviation is used as a dynamic threshold.

[0113] In some embodiments, the historical average memory usage is added to the historical standard deviation of memory by a preset multiple, and the sum is used as a dynamic threshold. The preset multiple is set according to actual needs.

[0114] In some embodiments, the method for calculating the dynamic threshold based on the historical mean memory usage and the historical standard deviation of memory usage can be expressed as: Threshold(t) = μ his +3*σ his Where Threshold(t) represents the dynamic threshold; μ his σ represents the historical average memory usage. his This represents the historical standard deviation of memory.

[0115] Step S33: Determine the memory leak result based on the memory prediction value and dynamic threshold.

[0116] The memory leak results include no memory leak, suspected memory leak, and confirmed memory leak.

[0117] In some embodiments, the method steps for determining a memory leak result based on a memory prediction value and a dynamic threshold specifically include: comparing the memory prediction value with the dynamic threshold; when the memory prediction value is less than or equal to the dynamic threshold in a time step, determining the memory leak result as a suspected memory leak; when the memory prediction value is greater than the dynamic threshold in a time step, determining the memory leak result as a suspected memory leak.

[0118] Furthermore, when the preset memory value exceeds the dynamic threshold for a consecutive preset number of time steps, the memory leak result is determined to be a confirmed memory leak. The preset number can be set according to actual needs; for example, it can be set to 3.

[0119] This application provides a memory leak detection method. It acquires process memory information, then predicts memory usage based on this information, and finally determines the memory leak result based on the predicted value to detect whether memory is leaking. Compared to traditional post-event analysis (such as checking logs after a program crash), this method acquires memory information in real time and predicts trends, providing early warning before memory leaks cause serious consequences (such as system lag or crashes), improving the timeliness of memory leak detection and reducing failure losses. The prediction model distinguishes between normal growth and leaky growth. For example, memory increases caused by loading data at program startup are normal, while continuous memory growth without release during long-term operation will be identified as a leak by the model, reducing false positives. This method can be set up to run on a cloud server, without relying on a specific programming language or framework; it can be applied as long as the process memory information of the terminal device can be obtained, reducing the computing power of the terminal device.

[0120] To better implement the memory leak detection method in this application embodiment, based on the memory leak detection method, this application embodiment also provides a memory leak detection device, such as... Figure 5 As shown, the memory leak detection device 200 includes:

[0121] Module 201 is used to obtain process memory information.

[0122] The prediction module 202 is used to make predictions based on process memory information to obtain memory prediction values.

[0123] Module 203 is used to determine the memory leak result based on the memory prediction value.

[0124] In this embodiment, process memory information is acquired, and then a memory prediction value is obtained based on the process memory information. The memory leak result is then determined based on the memory prediction value to detect whether memory is leaking. Compared to traditional post-event analysis (such as checking logs after a program crash), by acquiring memory information in real time and predicting trends, early warnings can be given before memory leaks cause serious consequences (such as system lag or crashes), improving the timeliness of memory leak detection.

[0125] In some embodiments, the prediction module 202 is specifically used to: preprocess the process memory information to obtain target memory time series data; decompose the target memory time series data to obtain an initial trend term and an initial residual term; and make a prediction based on the initial trend term and the initial residual term to obtain a memory prediction value.

[0126] In some embodiments, the prediction module 202 is further configured to: group and sort the process memory information to obtain initial memory timing data; obtain the maximum and minimum memory timing values ​​in the initial memory timing data; and standardize the initial memory timing data based on the maximum and minimum memory timing values ​​to obtain target memory timing data.

[0127] In some embodiments, the prediction module 202 is further configured to: calculate a first moving average based on the target memory time series data; calculate a second moving average based on the first moving average; calculate an initial trend term based on the first moving average and the second moving average; and calculate an initial residual term based on the target memory time series data and the initial trend term.

[0128] In some embodiments, the prediction module 202 is further configured to: make a prediction based on the initial trend term to obtain a predicted trend term; make a prediction based on the initial residual term to obtain a predicted residual term; and perform a fusion process on the predicted trend term and the predicted residual term to obtain a memory-predicted value.

[0129] In some embodiments, the prediction module 202 is further configured to: correct the initial trend term based on the historical trend term and the random error term to obtain the predicted trend term. The prediction module 202 is also further configured to: calculate the variance of the predicted trend term and the variance of the predicted residual term to obtain dynamic weights; and perform weighted calculations on the predicted trend term and the predicted residual term based on the dynamic weights to obtain the memory-predicted value.

[0130] In some embodiments, the prediction module 202 is further configured to: predict the residual term by modeling the initial residual term through a first processing model, the first processing model including: an input module, a state update module, and an output module; wherein, the input terminal of the input module is configured to receive the prediction result of the current time step and the state information of the previous time step, the output terminal of the input module is connected to the input terminal of the state update module, and the output terminal of the state update module is connected to the input terminal of the output module; the input module is configured to perform calculation processing on the prediction result of the current time step and the state information of the previous time step; the state update module is configured to perform calculation processing on the feature representation output by the input module and the memory information of the previous time step to obtain the memory information of the current time step; the output module is configured to perform calculation processing on the prediction result of the current time step, the state information of the previous time step, and the memory information of the current time step to obtain the state information of the current time step.

[0131] In some embodiments, the determining module 203 is specifically used to: obtain the historical average memory usage and the historical standard deviation of memory usage; calculate a dynamic threshold based on the historical average memory usage and the historical standard deviation of memory usage; and determine the memory leak result based on the memory prediction value and the dynamic threshold.

[0132] This application also provides a computer device that integrates any of the memory leak detection devices provided in this application. The computer device includes:

[0133] One or more processors;

[0134] Memory; and

[0135] One or more applications, wherein the applications are stored in memory and configured to be executed by a processor as steps in the memory leak detection method in any of the embodiments described above.

[0136] This application also provides a computer device that integrates any of the memory leak detection devices provided in this application. For example... Figure 6 As shown, it illustrates a structural schematic diagram of the computer device involved in the embodiments of this application, specifically:

[0137] The computer device may include components such as a processor 801 with one or more processing cores, a memory 802 with one or more computer-readable storage media, a power supply 803, and an input unit 804. Those skilled in the art will understand that... Figure 6 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:

[0138] The processor 801 is the control center of the computer device. It connects various parts of the computer device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 802, and by calling data stored in the memory 802, it performs various functions of the computer device and processes data, thereby providing overall monitoring of the computer device. Optionally, the processor 801 may include one or more processing cores; preferably, the processor 801 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 801.

[0139] The memory 802 can be used to store software programs and modules. The processor 801 executes various functional applications and data processing by running the software programs and modules stored in the memory 802. The memory 802 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 802 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 802 may also include a memory controller to provide the processor 801 with access to the memory 802.

[0140] The computer device also includes a power supply 803 that supplies power to the various components. Preferably, the power supply 803 can be logically connected to the processor 801 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 803 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0141] The computer device may also include an input unit 804, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0142] Although not shown, the computer device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 801 in the computer device loads the executable files corresponding to the processes of one or more application programs into the memory 802 according to the following instructions, and the processor 801 runs the application programs stored in the memory 802 to realize various functions, as follows:

[0143] Get process memory information;

[0144] Predictions are made based on process memory information to obtain predicted memory values;

[0145] Determine memory leak results based on memory prediction values.

[0146] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0147] Therefore, embodiments of this application provide a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), a disk, or an optical disk, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any of the memory leak detection methods provided in embodiments of this application. For example, the computer program loaded by the processor can execute the following steps:

[0148] Get process memory information;

[0149] Predictions are made based on process memory information to obtain predicted memory values;

[0150] Determine memory leak results based on memory prediction values.

[0151] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the detailed descriptions of other embodiments above, which will not be repeated here.

[0152] In practice, each of the above units or structures can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units or structures, please refer to the previous method embodiments, which will not be repeated here.

[0153] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0154] The above provides a detailed description of a memory leak detection method provided by the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A method for detecting memory leaks, characterized in that, include: Get process memory information; Based on the process memory information, a prediction is made to obtain the memory prediction value; The memory leak result is determined based on the predicted memory value.

2. The memory leak detection method according to claim 1, characterized in that, The prediction based on the process memory information to obtain a memory prediction value includes: The process memory information is preprocessed to obtain target memory timing data; The target memory time-series data is decomposed to obtain an initial trend term and an initial residual term; Based on the initial trend term and the initial residual term, a prediction is made to obtain the memory prediction value.

3. The memory leak detection method according to claim 2, characterized in that, The preprocessing of the process memory information to obtain target memory timing data includes: The process memory information is grouped and sorted to obtain initial memory timing data; Obtain the maximum and minimum memory timing values ​​from the initial memory timing data; The initial memory timing data is standardized based on the maximum and minimum memory timing values ​​to obtain the target memory timing data.

4. The memory leak detection method according to claim 2, characterized in that, The process of decomposing the target memory time-series data to obtain initial trend terms and initial residual terms includes: Calculate a moving average based on the target memory timing data; Calculate the second moving average based on the first moving average; The initial trend term is calculated based on the first moving average and the second moving average; The initial residual term is calculated based on the target memory timing data and the initial trend term.

5. The memory leak detection method according to claim 2, characterized in that, The prediction based on the initial trend term and the initial residual term to obtain the memory prediction value includes: Based on the initial trend term, a predicted trend term is obtained; Based on the initial residual term, a prediction residual term is obtained; The predicted trend term and the predicted residual term are fused to obtain the memory predicted value.

6. The memory leak detection method according to claim 5, characterized in that, The process of predicting a trend term based on the initial trend term includes: Based on the historical trend term and the random error term, the initial trend term is corrected to obtain the predicted trend term; The process of fusing the predicted trend term and the predicted residual term to obtain the memory-predicted value includes: The variance of the predicted trend term and the variance of the predicted residual term are calculated and processed to obtain the dynamic weights; The predicted trend term and the predicted residual term are weighted and calculated based on the dynamic weights to obtain the memory predicted value.

7. The memory leak detection method according to claim 5, characterized in that, The predicted residual term is obtained by modeling the initial residual term using a first processing model, which includes an input module, a state update module, and an output module. The input terminal of the input module is configured to receive the prediction result of the current time step and the state information of the previous time step. The output terminal of the input module is connected to the input terminal of the state update module, and the output terminal of the state update module is connected to the input terminal of the output module. The input module is configured to perform calculations on the prediction result at the current time step and the state information at the previous time step. The state update module is configured to calculate and process the feature representation output by the input module and the memory information of the previous time step to obtain the memory information of the current time step. The output module is configured to perform calculations on the prediction result of the current time step, the state information of the previous time step, and the memory information of the current time step to obtain the state information of the current time step.

8. The memory leak detection method according to claim 1, characterized in that, The determination of the memory leak result based on the memory prediction value includes: Obtain the historical mean and standard deviation of memory usage; Calculate the dynamic threshold based on the historical average memory usage and the historical standard deviation of memory usage; The memory leak result is determined based on the predicted memory value and the dynamic threshold.

9. A memory leak detection device, characterized in that, include: The acquisition module is used to obtain process memory information; The prediction module is used to make predictions based on the process memory information to obtain memory prediction values; The determination module is used to determine the memory leak result based on the memory prediction value.

10. A computer-readable storage medium, characterized in that, It stores a computer program, which is loaded by a processor to perform the steps of the memory leak detection method according to any one of claims 1 to 8.