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

Through real-time monitoring and data analysis, memory leaks in the vehicle's operating system were detected, resolving the issue of system resource exhaustion caused by memory leaks and enabling timely fault detection and optimization of user experience.

CN121524035APending Publication Date: 2026-02-13NIO TECH ANHUI CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511811893.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-03
Publication Date
2026-02-13

AI Technical Summary

Technical Problem

A memory leak exists in the vehicle's infotainment system, which reduces available memory resources and may cause system crashes, slow response times, and page freezes, resulting in a poor user experience.

Method used

By collecting memory usage data from multiple processes, memory usage is monitored in real time and stored in a memory data file. The memory data file is then used to identify target processes with memory anomalies, plot memory leak curves and standard deviations, screen out potential abnormal processes, and detect memory leaks in a timely manner.

Benefits of technology

Timely detection of memory leaks during process execution can prevent system crashes, slow responses, and page freezes, optimize user experience, and save system computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121524035A_ABST
    Figure CN121524035A_ABST
Patent Text Reader

Abstract

The invention provides a memory leak detection method and device, electronic equipment and a storage medium, and belongs to the technical field of automobiles, the method comprises the steps that a memory data file is acquired, and the memory data file comprises multiple pieces of memory use data of any one of multiple processes of the electronic equipment, the multiple pieces of memory use data of the same process correspond to different data acquisition periods; based on memory usage data corresponding to each process in different periods in the memory data file, determining at least one target process with memory abnormality in the plurality of processes; and performing memory leak detection on the at least one target process to determine the process with memory leak. By means of the scheme, whether the process has the memory leak or not can be judged by calling the memory use data in the memory data file in the process of running the process, the process with the memory leak can be captured in time without waiting for system running faults or system running ending, and user experience is optimized.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of automobiles, and particularly relates to a memory leakage detection method and device, an electronic device and a storage medium. BACKGROUND

[0002] Due to limited memory resources of a car machine, memory leakage has become a common problem in the running process of the operating system of the car machine. Memory leakage refers to that the operating system fails to correctly release the memory resources that are no longer used in the running process, resulting in a phenomenon that the available memory of the system gradually decreases. When memory leakage occurs, the memory will be continuously occupied, and the memory resources of the system will be excessively consumed, resulting in a problem of reduced available memory resources.

[0003] Since memory leakage will cause the available memory resources of the operating system to decrease when running, less memory resources may cause system crashes, slow responses, page lag and other bad experiences. Therefore, a memory detection method is urgently needed to timely discover the phenomenon of memory leakage in the operating system, so as to timely repair faults and ensure normal operation of the system. SUMMARY

[0004] The application aims to provide a memory leakage detection method and device, an electronic device and a storage medium, and aims to solve the problem that the conventional memory leakage cannot be timely monitored.

[0005] The first aspect of the application embodiment provides a memory leakage detection method, which comprises the following steps: obtaining a memory data file, wherein the memory data file comprises a plurality of memory usage data of any process in a plurality of processes of an electronic device, and the plurality of memory usage data of the same process correspond to different data collection periods; determining at least one target process with memory abnormality in the plurality of processes based on the memory usage data corresponding to different periods of each process in the memory data file; performing memory leakage detection on the at least one target process to determine a process with memory leakage.

[0006] In the embodiments of the present application, the memory usage of each process is monitored in real time by collecting the memory usage data of multiple processes, and the memory usage data of the multiple processes is stored in a memory data file, so as to determine at least one target process with memory exception based on the memory usage data in the memory data file, and then perform memory detection on the at least one target process, so as to determine the process with memory leakage. Thus, whether the process has memory leakage can be determined by calling the memory usage data in the memory data file during the running of the process, without waiting for the system to run or end, so that the process with memory leakage can be captured in time, and the user can detect the process failure in time, thereby preventing system crash, slow response, page lag and other problems caused by memory leakage, and optimizing the user experience.

[0007] In some embodiments, the memory leakage detection on the at least one target process to determine the process with memory leakage comprises: reading the memory usage data of at least one target process from the memory data file; drawing a memory leakage curve of at least one target process based on the memory usage data of at least one target process; any memory leakage curve is used to reflect the memory leakage trend of the target process; if the memory leakage curve of any target process meets the memory leakage characteristics, it is determined that any target process has memory leakage.

[0008] In the present implementation, by drawing the memory leakage curve of the target process, the memory leakage trend of the target process is represented by the memory leakage curve, and then it is determined whether the target process will have memory leakage. The memory usage of the process is displayed in the form of image, the memory usage of the process is visualized, the trend and fluctuation of memory usage are highlighted, and the user can clearly represent the change trend of memory occupation.

[0009] In some embodiments, the method further comprises: based on the memory usage data of any process collected, determining whether the memory occupation of any process has potential abnormality every preset data analysis period; if the memory occupation of any process has potential abnormality, grabbing the memory data of any process; storing the memory data of any process into the memory data file.

[0010] In the present implementation, whether the process has potential abnormality is determined by the memory usage increment of the process in adjacent data analysis periods, so that the running data of the process with potential abnormality is collected in time, so as to analyze the memory leakage of the process based on the running data subsequently.

[0011] In some embodiments, based on the memory usage data of any of the processes collected, it is determined whether the memory occupation of any of the processes has potential abnormality, comprising: For any of the processes, it is determined that the memory increment value between the memory usage data of the process collected in the Nth data analysis period and the memory usage data of the process collected in the N+1th data analysis period; If the memory increment value is greater than a preset increment value, it is determined that the memory occupation of any of the processes has potential abnormality.

[0012] In the present implementation, the memory usage increment value of the process in adjacent data analysis periods is used to determine whether the process has potential abnormality, so that the running data of the abnormal process can be collected in time, and the memory leakage analysis of the process can be performed based on the running data.

[0013] In some embodiments, the memory data file further comprises: running data of the processes in which the memory occupation has potential abnormality; and the method further comprises: For the process in which memory leakage occurs, the running data of the process is obtained from the memory data file; Based on the running data, the cause of the memory leakage of the process is determined.

[0014] In the present implementation, since the running data of the process with potential abnormality is collected in advance, when the process in which memory leakage occurs is detected, the running data of the process can be directly called to determine the cause of the memory leakage, thereby improving the efficiency of determining the cause of the memory leakage.

[0015] In some embodiments, based on the memory usage data of each of the processes in different periods in the memory data file, at least one target process in which memory abnormality exists is determined from the plurality of processes, comprising: Based on the memory usage data in the memory data file, the standard deviation of the memory usage of the plurality of processes is determined; Based on the standard deviation of the memory usage, at least one target process in which the standard deviation of the memory usage meets a preset condition is determined from the plurality of processes.

[0016] In the present implementation, the target processes in which memory abnormality possibly exists are screened from the plurality of processes based on the standard deviation of the memory usage of the processes, so that the target processes in which memory abnormality possibly exists are screened first before the memory leakage detection of the processes, thereby reducing the number of processes calculated in the memory leakage detection, and saving the computing resources in the system, and ensuring that the memory leakage can be detected during the operation of the system.

[0017] In some embodiments, the obtaining the memory data file comprises: periodically collecting memory usage data of each process based on a preset data collection period; storing the collected memory usage data in the memory data file.

[0018] In the present implementation, the memory usage data of each process is periodically collected and stored in the memory data file. In this way, the memory usage data of the processes is stored during the running of the system, so that the memory usage data of the processes can be analyzed to detect memory leakage during the running of the processes.

[0019] In some embodiments, the periodically collecting memory usage data of each process based on a preset data collection period comprises: periodically invoking a preset data collection command based on a preset data collection period, and obtaining initial memory usage data of the process by executing the preset data collection command; preprocessing the initial memory usage data to obtain valid memory usage data; combining the valid memory usage data to obtain the memory usage data of the process.

[0020] In the present implementation, the collected initial memory usage data is processed to remove invalid data in the initial memory usage data and only keep valid data in the memory usage data, thereby reducing the data of the memory usage data and further reducing the memory resources occupied by storing the memory usage data.

[0021] A second aspect of the embodiments of the present application provides a memory leakage detection device, and the device comprises: an obtaining unit configured to obtain a memory data file, wherein the memory data file comprises a plurality of memory usage data of any process in a plurality of processes of an electronic device, and the plurality of memory usage data of the same process correspond to different data collection periods; a first determining unit configured to determine at least one target process with memory anomaly in the plurality of processes based on the memory usage data corresponding to different periods of each process in the memory data file; a second determining unit configured to perform memory leakage detection on the at least one target process and determine a process with memory leakage.

[0022] In some embodiments, the second determining unit is configured to read memory usage data of at least one target process from the memory data file; draw a memory leak curve of the at least one target process based on the memory usage data of the at least one target process; any memory leak curve is used to reflect a memory leak trend of the target process; and if the memory leak curve of any target process meets a memory leak feature, it is determined that the target process has a memory leak.

[0023] In some embodiments, the apparatus further comprises: A third determining unit is configured to determine, based on the memory usage data of any process collected every preset data analysis period, whether the memory usage of any process has a potential abnormality. A data collecting unit is configured to collect memory data of any process if the memory usage of any process has a potential abnormality. A storage unit is configured to store the memory data of any process into the memory data file.

[0024] In some embodiments, the third determining unit is configured to determine, for any process, a memory increment value between the memory usage data of the process collected in an Nth data analysis period and the memory usage data of the process collected in an N+1th data analysis period; and if the memory increment value is greater than a preset increment value, it is determined that the memory usage of any process has a potential abnormality.

[0025] In some embodiments, the memory data file further comprises running data of the processes whose memory usage has a potential abnormality among the plurality of processes; and the apparatus further comprises: A calling unit is configured to obtain, for a process having a memory leak, running data of the process from the memory data file. A fourth determining unit is configured to determine, based on the running data, a cause of the memory leak of the process.

[0026] In some embodiments, the first determining unit is configured to determine, based on the memory usage data in the memory data file, a memory usage standard deviation of the plurality of processes; and determine, based on the memory usage standard deviation, at least one target process whose memory usage standard deviation meets a preset condition from the plurality of processes.

[0027] In some embodiments, the obtaining unit is configured to periodically collect memory usage data of each process based on a preset data collection period; and store the collected memory usage data in the memory data file.

[0028] In some embodiments, the obtaining unit is configured to periodically invoke a preset data collection command based on a preset data collection period, and obtain initial memory usage data of the process by executing the preset data collection command; preprocess the initial memory usage data to obtain valid memory usage data; and combine the valid memory usage data to obtain the memory usage data of the process.

[0029] A third aspect of the embodiments of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor implements the memory leakage detection method when executing the computer program.

[0030] A fourth aspect of the embodiments of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the memory leakage detection method.

[0031] A fifth aspect of the embodiments of the present application provides a computer program product, which, when running on an electronic device, causes the electronic device to execute the memory leakage detection method. BRIEF DESCRIPTION OF DRAWINGS

[0032] Figure 1 A flowchart of the memory leakage detection method provided by an example embodiment is shown; Figure 2 A schematic diagram of collecting memory usage data of a process during running of the process is shown; Figure 3 A flowchart of the memory leakage detection method provided by an example embodiment is shown; Figure 4 A schematic diagram of format content of initial memory usage data of n processes provided by an example embodiment is shown; Figure 5 A schematic diagram of content of the memory usage data after arrangement provided by an example embodiment is shown; Figure 6 A schematic diagram of content of the memory usage data provided by an example embodiment is shown; Figure 7 A schematic diagram of a memory leakage trend chart of a plurality of target processes provided by an example embodiment is shown; Figure 8 A flowchart of the memory leakage detection method provided by an example embodiment is shown; Figure 9 A schematic diagram of a method for obtaining running information of a process with memory exception provided by an example embodiment is shown; Figure 10 Fig. 1 shows a structural schematic diagram of a memory leakage detection device provided by an example embodiment; Figure 11 Fig. 2 is a structural schematic diagram of an electronic device provided by an example embodiment. DETAILED DESCRIPTION

[0033] In order to make the technical problems to be solved by the present application, technical solutions and beneficial effects clearer, the present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and not intended to limit the present application.

[0034] In addition, the terms "first", "second" are only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the features limited by "first", "second" can explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "a plurality of" is two or more, unless otherwise explicitly and specifically limited.

[0035] The car machine is an intelligent computing platform in the vehicle, the core of which is uniformly managed by the operating system hardware resources and software running; the operating system is responsible for scheduling memory resources, allocating running space for processes, and coordinating the concurrent execution of multiple application programs through a multi-task mechanism, and the application program exists in the form of a process in the memory as a specific function carrier, and the three form an organic whole through the resource management of the operating system, and jointly support the realization and performance optimization of the car machine function.

[0036] Due to the limited memory resources of the car machine, memory leakage has become a common problem in the running process of the car machine operating system. Among them, memory leakage refers to the phenomenon that the operating system fails to correctly release the memory resources that are no longer used during the running process, resulting in a gradual decrease in the available memory of the system. When memory leakage occurs, the memory will be continuously occupied, which will further consume the memory resources of the system, causing the problem of reducing the available memory resources.

[0037] Since memory leakage will cause the available memory resources of the operating system to decrease during running, insufficient memory resources may cause system crashes, slow response, page lag and other bad experiences, therefore, a memory detection method is urgently needed to timely discover the phenomenon of memory leakage in the operating system, so as to repair the fault in time and ensure the normal operation of the system.

[0038] The application provides a memory detection method and device, electronic equipment and a storage medium. The electronic equipment can be any device that manages hardware resources and software operation uniformly through an operating system. For example, the electronic equipment can be a mobile phone, a tablet computer or a smart device in a car system. The operating system in the electronic equipment can be any operating system. For example, the operating system can be an Android system or other operating systems developed on the basis of the Android system. In the embodiments of the application, the type of the operating system in the electronic equipment is not limited.

[0039] When the processes in the operating system control system run, the memory resources of the system are scheduled based on the requirements of the processes to ensure the normal running of the processes. The operating system schedules the memory resources, including allocating available free memory resources to the processes and releasing the memory resources that are not frequently used by the processes. In the embodiments of the application, the memory usage data of a plurality of processes is collected to monitor the memory occupation of each process in real time, and the memory usage data of the plurality of processes is stored in a memory data file, so as to determine at least one target process with a memory exception based on the memory usage data in the memory data file, and then perform memory detection on the at least one target process to determine the process with a memory leak. In this way, whether the process has a memory leak can be determined by calling the memory usage data in the memory data file during the running of the process, and the process with a memory leak can be captured in time without waiting for the system to run out of order or end running, so that the user can detect the process failure in time, thereby preventing system crashes, slow response, page lag and other problems caused by memory leaks, and optimizing the user experience.

[0040] The application will be described in detail below with reference to specific embodiments. Referring to Figure 1 which shows a flowchart of a memory detection method provided by an example embodiment. As an example but not limitation, the method is applied in an electronic equipment.

[0041] In S101, the electronic equipment acquires a memory data file, and the memory data file includes a plurality of memory usage data of any process in a plurality of processes of the electronic equipment. The plurality of memory usage data of the same process corresponds to different data collection periods.

[0042] Before this step, the electronic device periodically collects memory usage data of each process based on a preset data collection period; and stores the collected memory usage data in the memory data file. For multiple processes running in the system, the electronic device collects memory usage data of the processes every data collection period. For each process running in the system, the electronic device collects memory usage data of the process every data collection period. In some embodiments, the electronic device can determine the memory resources released and newly occupied by the process according to the memory usage data collected at different time points. In other embodiments, the electronic device can also determine the total memory resources, used memory resources and free memory resources of the operating system according to the memory usage data collected at the same time point by multiple processes. In this way, by periodically collecting memory data, the memory consumption of each process can be comprehensively monitored.

[0043] The data collection period can be set as needed, and in the embodiments of the present application, the data collection period is not specifically limited. For example, the data collection period can be 50 seconds, 55 seconds or 45 seconds, etc. See Figure 2 which shows a schematic diagram of memory usage data of a process collected every first preset time length during the running of the process according to an exemplary embodiment. As shown in Figure 2 , the memory usage data of the process is collected for the first time when the process starts running, and the memory usage data of the process is collected for the second time after the data collection period, and so on, and the memory usage data is collected every data collection period.

[0044] The memory usage data is data representing the occupation of memory resources by the process. For example, the memory usage data includes total memory resources, used memory resources and free memory resources. See Figure 3 which shows a flowchart of a memory detection method according to an exemplary embodiment. In some embodiments, the electronic device collects memory usage data of the process through a preset data collection command. However, since the data generated in the operating system has the characteristics of randomness, complexity, containing spaces, blank lines, misplacement, redundant values, etc., as shown in Figure 3 , the initial data collected needs to be cleaned and processed. Therefore, the process of obtaining memory usage data can be implemented through the following steps S1011-S1013, including: S1011, the electronic device periodically calls a preset data collection command based on a preset data collection period, and obtains initial memory usage data of the process by executing the preset data collection command.

[0045] The initial memory usage data can have the characteristics of irregular format, containing special characters, non-target data, etc. For example, see Figure 4which shows the format content of initial memory usage data of n processes provided by an example embodiment. As shown in Figure 4 The initial memory usage data includes multiple contents, such as Process Identifier (PID), Resident Set Size (RSS), Proportional Set Size (PSS), Unique Set Size (USS), memory size of the process swapped to the Swap Space (Swap), Proportional Swap (PSwap), Unique Swap (USwap), a specific memory area of the Linux kernel (Zswap), and the complete command line parameters (cmdline) when the process is started, and the like.

[0046] In S1012, the electronic device preprocesses the initial memory usage data of the process to obtain valid memory usage data.

[0047] Since the initial memory usage data includes invalid contents such as spaces, special symbols, and non-target data, in this step, the electronic device preprocesses the initial memory usage data to remove the invalid contents in the initial memory usage data. The preprocessing operation includes removing spaces, special symbols, non-target data, and the like.

[0048] In some embodiments, the electronic device further arranges the preprocessed memory usage data, including arranging the data format, combining the memory data of the process, setting the name of each content in the data, and the like. Referring to Figure 5 which shows the content in the arranged memory usage data provided by an example embodiment. As shown in Figure 5 The arranged memory usage data includes Name, PID, Vss (KB), Rss (KB), Pss (KB), and Uss (KB), and the like.

[0049] In S1013, the electronic device combines the valid memory usage data to obtain the memory usage data of the process.

[0050] In this step, based on the case identifier, the execution command time, and the like, the process name and the memory value are combined again, and each column of data is renamed to obtain the memory usage data. Referring to Figure 6The memory usage data includes a case identifier (Caseid), a timestamp, Name, PID, Vss (KB), Rss (KB), Pss (KB), and Uss (KB).

[0051] In the implementation, the initial memory usage data is processed to remove invalid data in the initial memory usage data and only keep valid data in the memory usage data, thereby reducing the data of the memory usage data and further reducing the memory resources occupied by storing the memory usage data.

[0052] The electronic device takes the first preset time length as a data collection period and cyclically executes the steps S1011-S1013 to meet the requirement of real-time acquisition of the memory usage data. After the electronic device collects the memory usage data of the processes, the memory usage data is stored in the memory data file.

[0053] It should be noted that when the electronic device stores the memory usage data of the plurality of processes in the memory data file, the memory usage data of the plurality of processes is packaged into data of the same format and then stored in the memory data file. The format of the data can be set as needed, and in the embodiments of the present application, the format of the data is not limited. For example, the format of the data can be CSV (Comma-Separated Values) format, wherein the CSV format is a lightweight pure text data format.

[0054] S102, the electronic device determines at least one target process with memory exception from the plurality of processes based on the memory usage data corresponding to each process in different periods in the memory data file.

[0055] The electronic device determines at least one target process with memory exception from the plurality of processes according to the memory usage data in the memory data file. In some embodiments, the electronic device can determine whether a process is a target process with memory exception according to the fluctuation degree of the memory usage of the process. Accordingly, the process can be implemented through the following steps S1021-S1022, including: S1021, the electronic device determines the memory usage standard deviation of the plurality of processes based on the memory usage data in the memory data file.

[0056] The standard deviation represents the fluctuation degree of the memory usage of the process. The greater the standard deviation, the greater the fluctuation degree of the memory usage of the process, and the more likely the process is to have a memory leak problem. Therefore, in the step, whether the process is a target process with memory exception is determined by determining the memory usage standard deviation of the process. The electronic device can determine the memory usage standard deviation through the following formula one.

[0057] Formula one:

[0058] wherein, represents the memory usage value of the process at each time point, represents the average value of the memory usage of the plurality of processes, represents the total number of single-process memory data (i.e., the number of memory usage data collected when calculating the standard deviation this time).

[0059] S1022, the electronic device determines at least one target process whose memory usage standard deviation satisfies a preset condition from the plurality of processes based on the memory usage standard deviation.

[0060] The preset condition can be set as needed, and in the embodiments of the present application, the preset condition is not specifically limited. For example, the preset condition can be a process whose standard deviation is greater than a preset standard deviation; or the preset condition can be a process that is ranked in the top N after sorting according to the standard deviation. The preset standard deviation can be set as needed, and in the embodiments of the present application, the preset standard deviation is not specifically limited. For example, the preset standard deviation can be 50 megabytes or 55 megabytes, etc. N is an integer greater than 0, and the value of N can be set as needed, and in the embodiments of the present application, the value of N is not specifically limited. For example, N can be 10, 15, or 12, etc.

[0061] In the present implementation, the memory usage standard deviation of the process is used to screen a plurality of target processes that may have memory abnormalities from the plurality of processes, so that a plurality of target processes that may have memory abnormalities are screened out first, and then the process memory leakage detection is performed, reducing the number of processes calculated during memory leakage detection, thereby saving computing resources in the system and ensuring that memory leakage can be detected during system operation.

[0062] S103, the electronic device performs memory leakage detection on the at least one target process, and determines a process that has memory leakage.

[0063] The electronic device can perform memory leakage detection on the target process according to a variety of methods. In some embodiments, the electronic device uses any memory leakage detection tool to perform memory leakage detection on the plurality of target processes. In other embodiments, the electronic device can draw a memory leakage trend chart according to the memory usage data of the target process, and determine whether the target process has memory leakage according to the memory leakage trend chart. This process can be implemented through the following steps S1031-S1033, including: S1031, the electronic device reads the memory usage data of at least one target process from the memory data file.

[0064] The memory usage data includes a process identifier, a process name, and the like for representing the process. The electronic device can call the memory usage data of the target process from the memory data file according to the process identifier or the process name of the target process.

[0065] In S1032, the electronic device draws a memory leak curve of the at least one target process based on the memory usage data of the at least one target process. Any memory leak curve is used to reflect a memory leak trend of the target process.

[0066] The electronic device can draw the memory leak curves of the plurality of target processes by using any drawing tool. For example, the electronic device can draw the memory leak curve of the target process based on STD (Standard).

[0067] Referring to Figure 7 , a plurality of memory leak curves of target processes are shown. As shown in Figure 7 , the plurality of memory leak curves of the target processes can be drawn in the same memory leak trend diagram. The memory curves of different target processes can be in different colors or different forms, which are not limited in the embodiments of the present application.

[0068] In S1033, if the memory leak curve of any target process meets a memory leak feature, it is determined that the target process has memory leak.

[0069] The memory leak feature is a feature of the trend of the memory curve in the memory leak trend diagram. For example, if the memory leak curve of a process shows a continuous growth trend and the process fails to release memory effectively, it is determined that the process has memory leak.

[0070] In some embodiments, the memory leak feature can be a memory leak feature summarized based on the memory leak trend diagrams of a plurality of processes that have memory leak. In some embodiments, a feature recognition model can be trained by the memory leak curves of the plurality of processes that have memory leak, and whether the memory leak curve of the target process meets the memory leak feature is identified based on the feature recognition model. For example, as shown in Figure 7 , the memory usage of process 1 is in an upward state, and it is determined that process 1 has memory leak. The memory usage of process 2 is stable, and there is no memory leak.

[0071] In the implementation, by drawing the memory leak curve of the target process, whether the target process has memory leak is represented by the memory leak curve, the memory usage of the process is displayed in the form of an image, the memory usage of the process is visualized, the trend and fluctuation of the memory usage are highlighted, and the user can clearly represent the change trend of the memory usage.

[0072] It should be noted that the electronic device periodically performs the above steps S101-S103 during stable operation of the system, so as to timely discover the memory leakage problem of any process in the electronic device. The period can be set according to the process, and in the embodiment of the present application, the period is not limited. For example, the period is 120 hours, 125 hours, etc.

[0073] In the embodiment of the present application, the memory usage data of a plurality of processes is collected to monitor the memory occupation of each process in real time, and the memory usage data of a plurality of processes is stored in a memory data file, so as to determine at least one target process with memory exception based on the memory usage data in the memory data file, and then perform memory detection on the at least one target process, so as to determine the process with memory leakage. In this way, during the running of the process, whether the process has memory leakage can be judged by calling the memory usage data in the memory data file, without waiting for the system to run to failure or the system to end running, so that the process with memory leakage can be captured in time, so that the user can detect the failure in time, thereby preventing system crash, slow response, page lag and other problems caused by memory leakage, and optimizing the user experience.

[0074] When detecting the process memory leakage, the cause of the memory leakage of the process needs to be determined, so as to solve the memory leakage problem. Therefore, the present application also provides a memory detection method, which analyzes the collected memory usage data of the process when collecting the memory usage data, and for the potential abnormal process, the running data of the process is captured for subsequent analysis of memory leakage and the like. Referring to Figure 8 which shows a flowchart of a memory detection method provided by an example embodiment. As an example but not limitation, the method is applied to an electronic device.

[0075] S801, based on the memory usage data of any process collected, determining whether the memory occupation of any process has potential abnormality.

[0076] The electronic device determines whether the memory occupation of the process is abnormal according to the memory usage data collected in the memory data file during the running of the system. In some embodiments, the electronic device determines whether the memory occupation of the process is abnormal according to the memory usage data collected in the data analysis period. The process can be implemented by the following steps S8011-S8012, comprising: S8011, the electronic device determines the memory increment between the memory usage data of the process collected in the Nth data analysis period and the memory usage data of the process collected in the N+1th data analysis period.

[0077] The electronic device can perform data analysis on the collected memory usage data every data analysis period, so as to determine the process that has memory usage anomaly, and accordingly, for any process, the electronic device acquires memory usage data of the process collected in a long data analysis period; determines the memory amount occupied by the process based on the memory usage data of the process collected in the data analysis period; and determines the memory increment of the process in two adjacent data analysis periods.

[0078] The data analysis period is greater than the data collection period, and in the embodiments of the present application, the data analysis period is not specifically limited. For example, the data analysis period can be 3600 seconds, 4000 seconds, 4500 seconds, or the like.

[0079] In S8012, if the memory increment is greater than a preset increment, the electronic device determines that the memory occupation of any process has potential anomaly.

[0080] The preset increment can be set as needed, and in the embodiments of the present application, the preset increment is not specifically limited. For example, the preset increment can be 100 M, 105 M, 120 M, or the like.

[0081] If the memory occupation of the process is abnormal, the electronic device performs S803, and if the memory occupation of the process is not abnormal, the electronic device does not perform S802, and continues to collect the memory usage data of the process regardless of whether the memory occupation of the process is abnormal.

[0082] In S802, if the memory occupation of any process has potential anomaly, the electronic device captures the running data of any process.

[0083] The running data includes stack trace, memory usage, process information, log, and the like of the process. The running data is used for subsequent determination of memory leakage, timely determination of the cause of memory leakage, and solution of the memory leakage problem.

[0084] The electronic device repeatedly performs S802, so as to timely find the process with memory anomaly. Referring to Figure 9 which shows a method for acquiring running information of a process with memory anomaly provided by an exemplary embodiment. As shown in Figure 9As shown, the memory usage data acquired first time is taken as P1, the memory usage data acquired second time is taken as P2, the increment E1 of P2 relative to P1 is determined, it is judged whether E1 is greater than a preset increment, if E1 is greater than the preset increment, the running data of the process is captured; the memory usage data acquired third time is taken as P3, the increment E2 of P3 relative to P2 is determined, it is judged whether E2 is greater than a preset increment, if E2 is greater than the preset increment, the running data of the process is captured; and so on, the memory usage data acquired (n-1)th time is taken as Pn-1, the memory usage data acquired nth time is taken as Pn, the increment En-1 of Pn relative to Pn-1 is determined, it is judged whether En-1 is greater than a preset increment, if En-1 is greater than the preset increment, the running data of the process is captured.

[0085] It should be noted that for the memory usage data collected in N data analysis periods, the electronic device can also determine the increment between the memory usage data acquired nth time Pn and the memory usage data acquired first time P1, if the increment is greater than a preset threshold, the process is determined as a target process. The preset threshold can be set as needed, and in the embodiment of the present application, the preset threshold is not specifically limited. For example, the preset threshold can be 500 or 800, etc.

[0086] In summary, for the same process, there can be abnormal memory usage data of the process at different times, and the running data of the process is acquired multiple times.

[0087] In the present implementation, the memory usage increment of the process in adjacent collection periods is used to determine whether the process is likely to be abnormal, so that the running data of the abnormal process is collected in time, so as to analyze the memory leakage of the process according to the running data subsequently.

[0088] S803, the electronic device stores the memory data of any process into the memory data file.

[0089] The electronic device stores the running data corresponding to the memory usage data corresponding to the process.

[0090] S804, the electronic device acquires a memory data file, the memory data file includes multiple memory usage data of any process in multiple processes of the electronic device, and the multiple memory usage data of the same process correspond to different data collection periods.

[0091] The principle of this step is the same as that of step S101, which will not be repeated here.

[0092] S805, the electronic device determines at least one target process with memory exception in multiple processes based on the memory usage data corresponding to each process in different periods in the memory data file.

[0093] The principle of this step is the same as that of step S102, and thus will not be described here.

[0094] S806, the electronic device performs memory leakage detection on the at least one target process to determine a process with memory leakage.

[0095] The principle of this step is the same as that of step S103, and thus will not be described here.

[0096] It should be noted that, in the present implementation, for a process with memory leakage, the running data of the process is obtained from the preset memory data file; and the cause of the memory leakage of the process is determined based on the running data.

[0097] The electronic device can call the running data of the process with memory leakage from the preset memory data file, and then show the running data to the user, so that the user can determine the cause of the memory leakage according to the running data. Alternatively, the electronic device can analyze the running data according to historical experience to obtain the cause of the memory leakage of the process.

[0098] In the embodiments of the present application, the memory usage data of a plurality of processes is collected to monitor the memory occupation of each process in real time, and the memory usage data of the plurality of processes is stored in a memory data file, so as to periodically determine a plurality of target processes with memory anomaly based on the memory usage data in the preset memory data file, and then perform memory detection on the plurality of target processes to determine a process with memory leakage. In this way, by storing the memory usage data of the process in the memory data file, whether the process has memory leakage can be determined by calling the memory usage data in the memory data file during the running of the process, without waiting for the system to run or end running. The process with memory leakage can be captured in time, so that the user can detect the process failure in time, thereby preventing system crashes, slow response, page lag and other problems caused by memory leakage, and optimizing the user experience.

[0099] It should be understood that the size of the serial number of each step in the above embodiments does not mean the order of execution, and the execution order of each process should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0100] Referring to Figure 10 which shows a structure schematic diagram of a memory leakage detection apparatus provided by the present application, each unit included therein is used to execute each step in the above embodiments, referring to Figure 10 The memory leakage detection apparatus includes: The acquisition unit 1001 is configured to acquire a memory data file, the memory data file including memory usage data of any process of a plurality of processes of an electronic device, and the memory usage data of the same process corresponding to different data collection periods; The first determination unit 1002 is configured to determine at least one target process with memory exception from the plurality of processes based on the memory usage data of each process corresponding to different periods in the memory data file. The second determination unit 1003 is configured to perform memory leak detection on the at least one target process to determine a process with memory leak.

[0101] In some embodiments, the second determination unit 1003 is configured to read the memory usage data of the at least one target process from the memory data file, draw a memory leak curve of the at least one target process based on the memory usage data of the at least one target process, and use any memory leak curve to reflect the memory leak trend of the target process. If any memory leak curve of the target process satisfies the memory leak feature, it is determined that any target process has memory leak.

[0102] In some embodiments, the apparatus further comprises: The third determination unit is configured to determine whether the memory usage of any process has potential exception based on the memory usage data of any process collected every preset data analysis period. The data collection unit is configured to collect the memory data of any process if the memory usage of any process has potential exception. The storage unit is configured to store the memory data of any process into the memory data file.

[0103] In some embodiments, the third determination unit is configured to determine the memory increment between the memory usage data of any process collected in the Nth data analysis period and the memory usage data of the process collected in the N+1th data analysis period, and determine that the memory usage of any process has potential exception if the memory increment is greater than a preset increment.

[0104] In some embodiments, the memory data file further includes running data of the process with potential exception in the memory usage of the plurality of processes, and the apparatus further comprises: The calling unit is configured to acquire the running data of the process with memory leak from the memory data file. The fourth determination unit is configured to determine the cause of the memory leak of the process based on the running data.

[0105] In some embodiments, the first determining unit 1002 is configured to determine, based on the memory usage data in the memory data file, a memory usage standard deviation of the plurality of processes; and determine, based on the memory usage standard deviation, at least one target process whose memory usage standard deviation satisfies a preset condition from the plurality of processes.

[0106] In some embodiments, the obtaining unit 1001 is configured to periodically collect memory usage data of each process based on a preset data collection period; and store the collected memory usage data in the memory data file.

[0107] In some embodiments, the obtaining unit 1001 is configured to periodically invoke a preset data collection command based on a preset data collection period, obtain initial memory usage data of the process by executing the preset data collection command; preprocess the initial memory usage data to obtain valid memory usage data; and combine the valid memory usage data to obtain the memory usage data of the process. In the embodiments of the present application, the memory usage data of a plurality of processes is collected to monitor the memory usage of each process in real time, and the memory usage data of the plurality of processes is stored in the memory data file, so as to determine at least one target process with memory exception based on the memory usage data in the memory data file, and then perform memory detection on the at least one target process to determine the process with memory leak. In this way, whether the process has memory leak can be determined by invoking the memory usage data in the memory data file during the running of the process, without waiting for the system to run out of order or the system to end running, so that the process with memory leak can be captured in time, and the user can detect the fault in time, thereby preventing system crash, slow response, page lag and other problems caused by memory leak, and optimizing the user experience.

[0108] Figure 11 is a schematic diagram of an electronic device provided by an example embodiment of the present application. As shown in Figure 11 the electronic device 11 of the embodiment includes a processor 110, a memory 111, and a computer program 112 stored in the memory 111 and executable on the processor 110, such as a memory detection program. The processor 110 implements the steps in each of the memory detection method embodiments described above when executing the computer program 112, such as the steps S201 to S203 shown in Figure 2 . Alternatively, the processor 110 implements the functions of each unit in each of the device embodiments described above when executing the computer program 112, such as the functions of the units 801 to 803 shown in Figure 8 .

[0109] For example, the computer program 112 can be divided into one or more units stored in the memory 111 and executed by the processor 110 to complete the present application. The one or more units can be a series of computer program instruction segments capable of completing a specific function, which are used to describe the execution process of the computer program 112 in the electronic device 11. For example, the computer program 112 can be divided into an acquisition unit, a first determination unit and a second determination unit, and the specific functions of each module are as follows: The acquisition unit 1001 is configured to acquire a memory data file, the memory data file including a plurality of memory usage data of any process of a plurality of processes of an electronic device, and the plurality of memory usage data of the same process corresponding to different data collection periods; The first determination unit 1002 is configured to determine at least one target process with memory exception from the plurality of processes based on the memory usage data corresponding to different periods of each process in the memory data file. The second determination unit 1003 is configured to perform memory leakage detection on the at least one target process to determine a process with memory leakage.

[0110] The electronic device 11 can be any electronic device with control function. The electronic device 11 can include, but is not limited to, a processor 110 and a memory 111. Those skilled in the art can understand that, Figure 11 The electronic device 11 is only an example and does not constitute a limitation on the electronic device 11, and can include more or fewer components than the illustration, or combine certain components, or different components, for example, the electronic device 11 can also include an input / output device, a network access device, a bus, etc.

[0111] The processor 110 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.

[0112] The storage 111 can be an internal storage unit of the electronic device 11, for example, a hard disk or a memory of the electronic device 11. The storage 111 can also be an external storage device of the electronic device 11, for example, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. equipped on the electronic device 11. Further, the storage 111 can include both the internal storage unit and the external storage device of the electronic device 11. The storage 111 is used to store the computer program and other programs and data required by the terminal device. The storage 111 can also be used to temporarily store data that has been output or will be output.

[0113] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above functional units and modules is exemplified, and in actual application, the above functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of software functional unit. In addition, the specific names of each functional unit and module are only for easy distinction, and do not limit the protection scope of the present application. The specific working process of the units and modules in the above system can refer to the corresponding process in the foregoing method embodiments, which will not be described here.

[0114] In the above embodiments, the description of each embodiment has its own emphasis, and the parts not described or recorded in detail in a certain embodiment can refer to the relevant description of other embodiments.

[0115] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized in electronic hardware or a combination of computer software and electronic hardware. Whether the functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0116] In the embodiments of the present application, it should be understood that the disclosed apparatus / terminal device and method can be implemented in other manners. For example, the described apparatus / terminal device embodiments are merely schematic. For example, the division of the modules or units is merely logical function division. There can be another division manner for actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between different units, can be indirect couplings or communication connections through some interfaces, devices or units.

[0117] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., can be located in one place, or can be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.

[0118] In addition, each functional unit in the various embodiments of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.

[0119] The integrated module / unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the above-mentioned embodiment methods can also be completed by a computer program instructing related hardware, and the computer program can be stored in a computer readable storage medium. When the processor executes the computer program, the steps of each method embodiment described above can be implemented. The computer program includes computer program code, which can be in the form of source code, object code, executable file or some intermediate form. The computer readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the computer readable medium can include appropriate contents according to the requirements of legislation and patent practice in the jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, the computer readable medium does not include electric carrier signal and telecommunication signal.

[0120] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program. The computer program is executed by a processor to implement the steps in the above-mentioned various method embodiments.

[0121] The embodiment of the present application further provides a computer program product. When the computer program product is run on a mobile terminal, the mobile terminal is enabled to implement the steps in the above-mentioned various method embodiments.

[0122] The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, but not limit the present application; although the present application is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalent features; and these modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.

Claims

1. A method for detecting memory leaks, characterized in that, The method includes: Acquire a memory data file, wherein the memory data file includes multiple memory usage data of any one of the multiple processes of the electronic device, and the multiple memory usage data of the same process correspond to different data acquisition cycles; Based on the memory usage data of each process in the memory data file at different periods, at least one target process with memory anomalies is identified among the multiple processes. Memory leak detection is performed on the at least one target process to identify processes with memory leaks.

2. The method as described in claim 1, characterized in that, The step of performing memory leak detection on the at least one target process to determine the process with a memory leak includes: Read at least one memory usage data of the target process from the memory data file; Based on the memory usage data of at least one of the target processes, a memory leak curve for at least one of the target processes is plotted; any one of the memory leak curves is used to reflect the memory leak trend of the target process. If the memory leak curve of any of the target processes satisfies the characteristics of a memory leak, then it is determined that any of the target processes has a memory leak.

3. The method as described in claim 1, characterized in that, The method further includes: Every preset data analysis period, based on the collected memory usage data of any of the processes, it is determined whether there are any potential anomalies in the memory usage of any of the processes; If the memory usage of any of the processes is potentially abnormal, capture the memory data of any of the processes. Store the RAM data of any of the processes in the memory data file.

4. The method as described in claim 3, characterized in that, The determination of whether there are potential anomalies in the memory usage of any of the processes based on the collected memory usage data includes: For any of the processes, determine the memory increment between the memory usage data of the process collected in the Nth data analysis cycle and the memory usage data of the process collected in the N+1th data analysis cycle; If the memory increment is greater than the preset increment, it is determined that the memory usage of any of the processes is potentially abnormal.

5. The method as described in claim 1, characterized in that, The memory data file also includes: runtime data of multiple processes whose memory usage is potentially abnormal; the method further includes: For processes with memory leaks, obtain the process's runtime data from the memory data file; The cause of the memory leak in the process was determined based on the runtime data.

6. The method as described in claim 1, characterized in that, The step of determining at least one target process among multiple processes that exhibits memory anomalies based on the memory usage data of each process in the memory data file at different periods includes: Based on the memory usage data in the memory data file, determine the standard deviation of memory usage for multiple processes; Based on the memory usage standard deviation, at least one target process whose memory usage standard deviation meets preset conditions is determined from among the multiple processes.

7. The method as described in claim 1, characterized in that, The acquisition of the memory data file includes: The memory usage data of each process is periodically collected based on a preset data collection cycle; The collected memory usage data is stored in the memory data file.

8. The method as described in claim 1, characterized in that, The process periodically collects memory usage data for each process based on a preset data collection cycle, including: Based on a preset data acquisition cycle, a preset data acquisition command is periodically invoked, and the initial memory usage data of the process is obtained by executing the preset data acquisition command; The initial memory usage data is preprocessed to obtain valid memory usage data; The valid memory usage data is combined to obtain the memory usage data of the process.

9. A memory leak detection device, characterized in that, The device includes: An acquisition unit is used to acquire a memory data file, wherein the memory data file includes multiple memory usage data of any one of the multiple processes of the electronic device, and the multiple memory usage data of the same process correspond to different data acquisition cycles; The first determining unit is used to determine at least one target process among the multiple processes that has memory anomalies based on the memory usage data of each process in the memory data file at different periods. The second determining unit is used to perform memory leak detection on the at least one target process and determine the process with a memory leak.

10. An electronic device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the memory leak detection method as described in any one of claims 1-8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, characterized in that, when the computer program is executed by a processor, it implements the memory leak detection method as described in any one of claims 1-8.

12. A computer program product, characterized in that, When the computer program product is run on an electronic device, the electronic device performs the memory leak detection method as described in any one of claims 1-8.