A memory leak processing method and an electronic device

By transferring the application data that leaked memory to a Swap partition or external storage and then saving it back to memory when it is called again, the system performance problem caused by memory leaks is solved, and the operating efficiency of electronic devices is improved.

CN115934302BActive Publication Date: 2026-01-09HONOR DEVICE CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202110886939.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-03
Publication Date
2026-01-09
Estimated Expiration
2041-08-03

AI Technical Summary

Technical Problem

Memory leaks in electronic devices can lead to insufficient system memory, affecting system performance and causing problems such as lag.

Method used

The memory data of the process of the application with memory leaks is transferred to a location other than memory, such as the Swap partition or external storage, and then transferred back to memory when the memory data is accessed again.

Benefits of technology

It increases the memory storage space of electronic devices, avoids insufficient memory and lag, and improves the performance of the devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115934302B_ABST
    Figure CN115934302B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a memory leakage processing method and an electronic device, and relate to the technical field of terminals, which can increase the available memory of the electronic device, thereby improving the use performance of the electronic device. The electronic device comprises at least one process, and the at least one process comprises a first process, and the method comprises: if it is determined that the memory satisfies a first preset condition, obtaining memory data corresponding to the first process; the first preset condition comprises that the first process has memory leakage; and storing the memory data corresponding to the first process in a temporary storage area; wherein the temporary storage area is a storage area other than the memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of terminal technology, and in particular to a memory leak handling method and electronic device. Background Technology

[0002] With the development of electronic devices, various applications (APPs) have emerged in endless streams, allowing users to handle many tasks on their electronic devices and providing convenience. However, if an application allocates memory but does not use it for an extended period without releasing it, it will lead to a continuous shortage of system memory, affecting system operation and resulting in a serious memory leak problem. This will cause performance issues such as lag when using the application, thus impacting the overall performance of the electronic device.

[0003] However, in related technologies, how to handle the situation after detecting memory leaks in applications within electronic devices is an important problem that needs to be solved. Summary of the Invention

[0004] This application provides a memory leak handling method and an electronic device. By swapping the memory data corresponding to the process of an application with a memory leak to a location other than memory, such as a Swap partition or external storage, the electronic device can have sufficient memory, thereby improving its performance.

[0005] To achieve the above objectives, this application adopts the following technical solution:

[0006] On one hand, this application provides a memory leak handling method applied to an electronic device. The electronic device includes at least one process, and the at least one process includes a first process. The method includes: if it is determined that the memory meets a first preset condition, then obtaining the memory data corresponding to the first process; meeting the first preset condition includes the first process having a memory leak; transferring the memory data corresponding to the first process to a temporary storage area; wherein, the temporary storage area is a storage area other than memory.

[0007] Therefore, after determining that there is a memory leak in the first process, the memory data of the first process is transferred out of memory, which increases the memory storage space of the electronic device and thus improves the performance of the electronic device.

[0008] In one possible implementation, satisfying the first preset condition includes: at least one of the system's available storage, the available storage of the temporary storage area, and the memory occupancy rate of the first process satisfies the first preset condition.

[0009] Therefore, after determining that there is a memory leak in the first process, and when the first preset condition is met, the memory data of the first process is transferred to the temporary storage area, thereby increasing the memory storage space of the electronic device and thus improving the performance of the electronic device.

[0010] In another possible implementation, satisfying the first preset condition includes: the available storage of the system is less than or equal to a first storage threshold.

[0011] Therefore, when it is determined that the available storage capacity of the current system is small and will affect the performance of the electronic device, the memory data of the first process is transferred to the temporary storage area, thereby increasing the available storage capacity of the electronic device system.

[0012] In another possible implementation, satisfying the first preset condition also includes: the available storage amount in the temporary storage area is greater than the second storage amount threshold and / or the occupancy rate is less than the occupancy rate threshold.

[0013] Therefore, when it is determined that the temporary storage area has sufficient space to store the memory data of the first process and / or the memory usage rate of the first process is low, the memory data of the first process is transferred to the temporary storage area, thereby improving the performance of the electronic device while ensuring its normal operation.

[0014] In another possible implementation, the method further includes: if the available storage of the system is greater than the first storage threshold, or the available storage of the temporary storage area is less than or equal to the second storage threshold, or the occupancy rate is greater than or equal to the occupancy rate threshold, then report the status that the memory data corresponding to the first process has not been transferred.

[0015] Therefore, if the first preset condition is not met, the memory data corresponding to the first process will not be transferred to ensure the normal operation of the electronic device.

[0016] In another possible implementation, the memory data corresponding to the first process is transferred to a temporary storage area, including: obtaining the memory information of the first process; wherein the memory information includes the memory acquisition time and the corresponding memory usage; determining the memory amount of the memory data corresponding to the first process based on the memory leak rate and / or memory usage of the first process; wherein the memory leak rate is determined based on the memory acquisition time and the corresponding memory usage; and transferring the memory data corresponding to the first process in units of memory usage until the amount of memory data corresponding to the first process stored in the temporary storage area is greater than or equal to the memory amount of the memory data.

[0017] Therefore, batch transferring the memory data corresponding to the first process can improve the efficiency of data transfer.

[0018] In another possible implementation, the memory data includes anonymous pages. The memory data corresponding to the first process is transferred to a temporary storage area, which includes: transferring anonymous pages to the temporary storage area according to their priority order; wherein the priority order is that the anonymous page that has not been called within a preset time period has a higher priority than the anonymous page that was first added to the secondary recycling list, and the anonymous page that was first added to the secondary recycling list has a higher priority than the anonymous page that has not been called by multiple processes at the same time.

[0019] Therefore, anonymous pages are transferred according to their priority order, with priority given to anonymous pages that have not been used for a long time, so that electronic devices can operate normally.

[0020] In another possible implementation, after transferring the memory data corresponding to the first process to the temporary storage area, the method further includes: transferring the memory data corresponding to the first process from the temporary storage area to memory.

[0021] Therefore, when it is determined that the memory data corresponding to the first process stored in the temporary storage area is called again, the memory data corresponding to the first process is transferred from the temporary storage area to the main memory, thereby enabling the electronic device to operate normally.

[0022] In another possible implementation, the memory data corresponding to the first process is transferred from the temporary storage area to main memory. This includes: if the memory data corresponding to the first process is accessed, querying the memory address table to obtain the second storage address of the memory data in the temporary storage area; wherein the memory address table records the correspondence between the first storage address of the memory data in main memory and the second storage address in the temporary storage area; after obtaining the memory data from the second storage address, the memory data is transferred to the storage area in main memory. The storage area in main memory can be the storage area corresponding to the first storage address, or it can be a different storage area; this is not limited here.

[0023] Therefore, when memory data stored in the temporary storage area is retrieved again, the electronic device can operate normally by transferring the memory data from the temporary storage area to the memory storage area.

[0024] In another possible implementation, before transferring the memory data corresponding to the first process to the temporary storage area, the process further includes compressing the memory data corresponding to the first process. This reduces the storage space occupied in the temporary storage area by compressing the memory data transferred to it.

[0025] In another possible implementation, after retrieving memory data from the second storage address, the memory data is transferred to the memory storage area, including: decompressing the memory data retrieved from the second storage address; and transferring the decompressed memory data to the memory storage area. Thus, if the memory data stored in the temporary storage area is compressed, it is decompressed before being transferred to memory to obtain the memory data of the first process.

[0026] In another possible implementation, after transferring the memory data corresponding to the first process to the temporary storage area, the method further includes: obtaining the available storage amount of the temporary storage area; if the available storage amount of the temporary storage area is less than or equal to a third storage threshold, then transferring the memory data stored in the temporary storage area to the buffer.

[0027] Therefore, when the available storage capacity of the temporary storage area is small, performing a secondary transfer of the data stored in the temporary storage area can free up storage space in the temporary storage area and increase the available storage capacity of the temporary storage area.

[0028] In another possible implementation, before transferring the memory data corresponding to the first process to the temporary storage area, the method further includes: displaying a prompt message; wherein the prompt message is used to prompt the user whether to transfer the memory data corresponding to the first process out of memory.

[0029] Therefore, by prompting users on the electronic device's display interface whether to handle processes with memory leaks, users can take appropriate action based on the prompts, thus avoiding performance issues such as insufficient memory or lag in the electronic device.

[0030] In another possible implementation, at least one process further includes a second process, which determines that the memory meets a first preset condition. Meeting the first preset condition includes the existence of a memory leak in the first process, including: obtaining first memory information corresponding to the first process and second memory information corresponding to the second process; determining, based on the first memory information corresponding to the first process and the second memory information corresponding to the second process, whether the first process meets the second preset condition or whether the second process does not meet the second preset condition; obtaining third memory information corresponding to the first process; and determining, based on the third memory information corresponding to the first process, that the first process has a memory leak.

[0031] Therefore, we can first identify the first process in the electronic device that may have a memory leak, and then determine the existence of a memory leak in the first process based on the memory information corresponding to the first process. This can accurately detect processes with memory leaks, so that appropriate actions can be taken to deal with the processes with memory leaks, thereby improving the performance of the electronic device.

[0032] In another possible implementation, the first memory information includes the first memory acquisition time and the corresponding first memory usage. Determining that the first process meets the second preset condition includes: determining that the first process meets the second preset condition based on the first memory increase rate and / or the first total memory usage of the first process; wherein the first memory increase rate is determined based on at least two first memory acquisition times and the corresponding first memory usage of the first process; and the first total memory usage is determined based on the first memory usage.

[0033] Therefore, by using the first memory increase rate and / or the first total memory usage of the first process, it can be determined that the first process has a memory leak, and the process that may have a memory leak in the electronic device can be accurately detected.

[0034] In another possible implementation, the first process is determined to meet the second preset condition based on the first memory increase rate and / or the first total memory usage, including: if the first memory increase rate of the first process is greater than the first rate threshold and / or the first total memory usage is greater than the usage threshold, then the first process is determined to meet the second preset condition.

[0035] Therefore, by identifying processes with excessively high memory growth rates and / or high total memory usage as potentially memory-leaking processes, it is possible to accurately detect processes in electronic devices that may have memory leaks.

[0036] In another possible implementation, the third memory information includes the second memory acquisition time and the corresponding second memory usage. Based on the third memory information corresponding to the first process, it is determined that the first process has a memory leak, including: determining that the first process has a memory leak based on at least one of the first process's second memory increase rate, average memory increase rate, and total second memory usage; wherein, the second memory increase rate is determined based on at least two second memory acquisition times and the corresponding second memory usage of the first process; the average memory increase rate is determined based on at least one second memory increase rate; and the total second memory usage is determined based on the second memory usage.

[0037] Therefore, by measuring the memory increase rate and / or total memory usage of the first process, it is possible to accurately determine whether the first process has a memory leak.

[0038] In another possible implementation, the existence of a memory leak in the first process is determined based on at least one of the second memory increase rate, the average memory increase rate, and the second total memory usage, including: if the average memory increase rate of the first process is greater than or equal to the second rate threshold, then the existence of a memory leak in the first process is determined.

[0039] Therefore, the first process, which continuously requested a large amount of memory in a short period of time, was identified as having a memory leak, and the existence of a memory leak in the first process was accurately determined.

[0040] In another possible implementation, determining that the first process has a memory leak based on at least one of the second memory increase rate, the average memory increase rate, and the second total memory usage of the first process further includes: if the average memory increase rate of the first process is less than the second rate threshold, and the number of second memory increase rates is greater than the first number threshold, and a consecutive preset number of second memory increase rates are all greater than the third rate threshold, then the first process has a memory leak; wherein the third rate threshold is less than the second rate threshold.

[0041] Therefore, by determining that although the first process did not request a large amount of memory in a short period of time, it continuously requested memory from the system, and the amount of memory requested was continuously increasing, it was possible to accurately determine that the first process had a memory leak.

[0042] In another possible implementation, determining that the first process has a memory leak based on at least one of the second memory increase rate, the average memory increase rate, and the second total memory usage of the first process further includes: if the average memory increase rate of the first process is less than the second rate threshold, and the number of second memory increase rates is greater than the first number threshold, and at least one of the consecutive preset number of second memory increase rates is less than the third rate threshold, and the second total memory usage is greater than the memory threshold, then determining that the first process has a memory leak.

[0043] Therefore, by determining that although the first process did not request a large amount of memory in a short period of time, it continuously requested memory from the system and the total amount of memory requested was relatively large, it was also possible to accurately determine that the first process had a memory leak.

[0044] On the other hand, this application provides an electronic device, including: a memory reclamation module, used to determine that a first process has a memory leak and meets a first preset condition, then obtain the memory data corresponding to the first process; and transfer the memory data corresponding to the first process to a temporary storage area; wherein, the temporary storage area is a storage area other than memory.

[0045] In another aspect, this application provides an electronic device, including: a memory, a display screen, and one or more processors; the memory, the display screen, and the processors are coupled. The memory stores computer program code, which includes computer instructions; when the electronic device is running, the processor executes one or more computer instructions stored in the memory to cause the electronic device to perform a memory leak handling method as described in any of the preceding aspects.

[0046] In another aspect, this application provides a computer storage medium including computer instructions that, when executed on an electronic device, cause the electronic device to perform a memory leak handling method as described in any of the preceding aspects.

[0047] In another aspect, this application provides a computer program product that, when run on an electronic device, causes the electronic device to perform a memory leak handling method as described in any of the above aspects.

[0048] Understandably, the electronic devices, computer storage media, and computer program products provided above are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here. Attached Figure Description

[0049] Figure 1 Examples of application scenarios for memory leaks provided in the embodiments of this application Figure 1 ;

[0050] Figure 2 Examples of application scenarios for memory leaks provided in the embodiments of this application Figure 2 ;

[0051] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0052] Figure 4 A software structure diagram of an electronic device provided in an embodiment of this application;

[0053] Figure 5 Examples of application scenarios for the memory leak handling method provided in the embodiments of this application Figure 1 ;

[0054] Figure 6 A flowchart of a memory leak handling method provided in this application embodiment. Figure 1 ;

[0055] Figure 7 A flowchart of a memory leak handling method provided in this application embodiment. Figure 2 ;

[0056] Figure 8 An example diagram of an interface call provided in an embodiment of this application;

[0057] Figure 9A Examples of application scenarios for the memory leak handling method provided in the embodiments of this application Figure 2 ;

[0058] Figure 9BExamples of application scenarios for the memory leak handling method provided in the embodiments of this application Figure 3 ;

[0059] Figure 10 A flowchart illustrating the memory swapping process provided in this application embodiment;

[0060] Figure 11 Examples of application scenarios for the memory leak handling method provided in the embodiments of this application Figure 4 ;

[0061] Figure 12 This is another structural schematic diagram of the electronic device provided in the embodiments of this application. Detailed Implementation

[0062] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; the term "and / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone.

[0063] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of embodiments of this application, unless otherwise stated, "a plurality of" means two or more.

[0064] In the embodiments of this application, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design that is described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design. Specifically, the use of the terms "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.

[0065] Before describing the embodiments of this application, the terms involved in this application will be explained.

[0066] Memory, also known as internal memory, refers to the storage space that the central processing unit (CPU) can directly address, and it has the advantage of high access speed. Memory includes random access memory (RAM), read-only memory (ROM), and cache memory.

[0067] External storage, also known as external memory, refers to storage devices other than the main memory and CPU cache of electronic devices. These devices generally retain data even after power is lost. Common external storage devices include hard drives, floppy disks, optical discs, and USB flash drives.

[0068] Memory compression refers to the act of compressing memory pages to free up memory space. For example, when the system's memory usage is too high, it compresses a large number of memory pages that are rarely accessed or temporarily not used, thereby freeing up memory space. For instance, suppose memory page A originally occupied 1GB of memory; after memory compression, this memory page only occupies 500MB of memory, thus freeing up some memory space and saving system memory.

[0069] Swap partition, also known as a swap space, refers to a portion of hard drive space released when the system's physical memory is insufficient, making it available for currently running programs. This released space may come from programs that haven't been used for a long time. This released space is temporarily saved to the swap partition, and the saved data is restored to memory from the swap partition when those programs need to run. In other words, swap space is only used when physical memory and cache memory are insufficient. The swap partition can be a portion of virtual memory or a portion of secondary storage; this is not a limitation.

[0070] A page is a segment or page that divides memory space into pieces based on page size. One page can correspond to multiple memory segments, and the smallest segment can range from 8K to 128K, depending on the memory management mechanism.

[0071] For example, suppose a page has a memory page number of 0001. This page may include multiple memory segments, such as 0x0001, 0x0002, and 0x0003, etc.

[0072] Currently, applications on electronic devices may allocate memory within a short period, and then stop using that memory after use or when the application goes into the background. However, if the application doesn't release the allocated memory and continues to occupy it, it can lead to memory leaks. When other applications on the same electronic device start up in this situation, it can cause insufficient available memory or performance issues such as lag.

[0073] For example, such as Figure 1 The image shown is an example of an application scenario involving memory leaks. Assume... Figure 1 The maximum available memory of the electronic device is 8GB. When application A is launched, it requests up to 5GB of memory from the system within a short period (e.g., 3 minutes). At this time, the electronic device has 3GB of available memory remaining. After application A finishes use or enters the background, it no longer needs the 5GB of memory. However, application A continues to occupy this memory for an extended period without releasing it. In this case, application A has a memory leak. After other applications are launched on the electronic device, the device may experience insufficient available memory. Figure 1 In this scenario, after launching application A, the user then launches applications B and C. When application B launches, it requests 1GB of memory from the system, and when application C launches, it requests 2GB. At this point, the electronic device has applications A, B, and C running. Application A uses 5GB of memory, application B uses 1GB, and application C uses 2GB. In this situation, the applications already running on the electronic device are using a total of 8GB of memory, leaving 0GB of available memory. This results in insufficient available memory, potentially causing performance issues such as lag or stuttering during the operation of applications B and C, or other newly launched applications.

[0074] In related technologies, when a memory leak is detected in an application on an electronic device, the traditional approach is mostly to directly release the memory that the application has been occupying for a long time. However, after the application's memory is released, the system is unaware that the memory occupied by the application has been released, leading to application addressing errors when the application tries to access that memory again. In this case, not only will data be lost, but the normal use of the electronic device will also be affected.

[0075] For example, such as Figure 2 As shown, after application A in the electronic device experiences a memory leak, it directly releases 2GB of memory. After application A releases the 2GB of memory, the system is unaware that the 2GB of memory has been released. When application A tries to access memory again, if it directly accesses the already released 2GB of memory, an addressing error will occur, affecting the normal operation of application A.

[0076] This application provides a method for handling memory leaks. The method involves transferring the memory data corresponding to the process of an application with a memory leak to a location outside of main memory, such as a swap partition or secondary storage. When this memory data is accessed again, it is then transferred back to main memory. The application can be a system application or a third-party application (e.g., an application downloaded from an app store or app market on an electronic device). This method can restore the memory of processes with memory leaks, preventing applications with memory leaks from failing to function properly and improving the performance of electronic devices.

[0077] For example, the memory leak handling method provided in this application embodiment can be applied to electronic devices with displays such as mobile phones, tablets, personal computers (PCs), personal digital assistants (PDAs), smartwatches, netbooks, wearable electronic devices, augmented reality (AR) devices, virtual reality (VR) devices, in-vehicle devices, smart cars, and smart speakers. This application embodiment does not impose any limitations on this.

[0078] For example, Figure 3 This is a schematic diagram of the structure of an electronic device 100 provided in an embodiment of this application. Figure 3 As shown, the electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.

[0079] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0080] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0081] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.

[0082] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0083] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0084] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.

[0085] The charging management module 140 receives charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 receives charging input from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 receives wireless charging input via the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also supply power to the electronic device via the power management module 141.

[0086] The power management module 141 connects the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, providing power to the processor 110, internal memory 121, external memory, display screen 194, camera 193, and wireless communication module 160, etc. The power management module 141 can also monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage current, impedance). In some other embodiments, the power management module 141 may also be located within the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may be located in the same device.

[0087] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.

[0088] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.

[0089] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Mini LED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1.

[0090] Electronic device 100 can perform shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.

[0091] The ISP (Image Signal Processor) is used to process data fed back from the camera 193. For example, when taking a picture, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, and the camera's photosensitive element transmits the electrical signal to the ISP for processing, transforming it into an image visible to the naked eye. The ISP can also perform algorithmic optimization of image noise, brightness, and skin tone. The ISP can also optimize parameters such as exposure and color temperature of the shooting scene. In some embodiments, the ISP can be set in the camera 193.

[0092] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into image signals in standard RGB, YUV, or other formats. In some embodiments, the electronic device 100 may include one or N cameras 193, where N is a positive integer greater than 1.

[0093] Digital signal processors (DSPs) are used to process digital signals. Besides digital image signals, they can also process other digital signals. For example, when electronic device 100 selects a frequency, the DSP can perform Fourier transforms on the frequency energy.

[0094] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. Thus, electronic device 100 can play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0095] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.

[0096] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.

[0097] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.). Furthermore, internal memory 121 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, universal flash storage (UFS), etc.

[0098] Internal memory 121, also known as RAM, is used to store information during system operation. In this embodiment, when a user launches an application in an electronic device, the application requests corresponding memory from the system. After the application requests memory, if a memory leak is detected, the system can transfer a portion of the application's memory data to a temporary storage area. For example, when a user launches application B, application B requests 3GB of memory from the system; when a user launches application D, application D requests 1.5GB of memory from the system, and so on. Assuming the system determines that application B has a memory leak, it can transfer a portion of application B's memory to a temporary storage area.

[0099] It should be noted that the amount of memory requested by the system when the application starts is only an example. The amount of memory requested by the application when starting depends on the actual situation and is not limited here.

[0100] In this embodiment, the processor 110, by executing instructions stored in the internal memory 121, can first transfer the memory data of the application with memory leaks to a location outside of memory, such as a swap partition or secondary storage, to free up the application's memory space. When the application calls this memory data again, it then transfers the memory data back to the electronic device's memory. Thus, by restoring the memory of the application with memory leaks, the application can run normally when it calls this memory data again.

[0101] The software system of an electronic device can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This embodiment of the invention uses the layered architecture Android system as an example to exemplify the software structure of the electronic device 100.

[0102] Figure 4 This is a software structure diagram of an electronic device provided in an embodiment of this application.

[0103] Understandably, a layered architecture divides software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system may include an application layer (referred to as the application layer), an application framework layer (referred to as the framework layer), the Android runtime, system libraries, and the kernel layer. The application layer may include a series of application packages.

[0104] like Figure 4 As shown, the application package includes system applications. System applications are those pre-installed on the phone before it leaves the factory. For example, system applications may include settings, phone manager, camera, gallery, calendar, music, SMS, and call programs.

[0105] Application packages can also include third-party applications, which are applications that users install after downloading and installing them from an app store (or app market). For example, map applications (such as Baidu Maps). Gaode Map (etc.), food delivery apps (such as app D, Ele.me) Reading applications (such as e-books) ), social applications (such as application B), and ride-hailing applications (such as Didi Chuxing). )wait.

[0106] The application framework layer described above provides an application programming interface (API) and programming framework for applications in the application layer. The application framework layer includes some predefined functions.

[0107] like Figure 4 As shown, the application framework layer may include a window manager, content provider, view system, phone manager, resource manager, notification manager, etc.

[0108] The window manager is used to manage windowed applications. It can retrieve screen size, determine the presence of a status bar, lock the screen, and capture screenshots, among other things.

[0109] Content providers store and retrieve data, making that data accessible to applications. This data can include videos, images, audio, phone calls made and received, browsing history and bookmarks, phone books, and more.

[0110] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon could include views for displaying text and views for displaying images.

[0111] The phone manager is used to provide communication functions for electronic device 100. For example, it manages call status (including connection and disconnection).

[0112] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, and more.

[0113] The notification manager allows applications to display notifications in the status bar. These notifications can be used to deliver informational messages and can disappear automatically after a short pause, requiring no user interaction. For example, the notification manager can be used to notify users of completed downloads or message alerts. The notification manager can also display notifications as icons or scrolling text in the top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting sounds, vibrating electronic devices, and flashing indicator lights.

[0114] In this embodiment, the notification manager can display a notification in the status bar when memory with a memory leak has been swapped out. The Android Runtime includes core libraries and a virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.

[0115] The core library consists of two parts: one part is the functionalities that need to be called by the Java language, and the other part is the Android core library.

[0116] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.

[0117] like Figure 4 As shown, the system library can include multiple functional modules. For example: a daemon process module, a leaked process distribution module, a scheduling module, and a log processing module.

[0118] The daemon module is a key module for maintenance and testing. It exists independently of the native Android system as a daemon process, starting with the entire system upon boot and running until shutdown. The daemon module's architecture is situated above the kernel layer and below the application layer in the native framework layer.

[0119] Among them, a daemon process is a process that is detached from the control electronic device and periodically performs a certain task or waits to process certain events in the background. It is detached from the terminal to prevent the information of the process during execution from being displayed on any terminal and to prevent the process from being terminated by any terminal interrupt information.

[0120] In another scenario, if the system layer does not have a daemon module, a mechanism similar to a daemon will be rebuilt and placed in the local framework layer above the kernel layer and below the application layer, without conflicting with Android's native code and capabilities.

[0121] This application uses an Android system with a daemon process module as an example to illustrate the software structure of an electronic device.

[0122] like Figure 4 As shown, the daemon module includes a runtime management module, which in turn includes a memory leak detection module.

[0123] The memory leak detection module is used to detect memory leaks in the processes of electronic devices to determine whether there are memory leaks in the running processes.

[0124] The leak process distribution module is used to distribute the process identifier (e.g., process ID and / or process name) corresponding to the process that has a memory leak.

[0125] In this embodiment of the application, after the memory leak detection module detects that a process of the electronic device has a memory leak, it sends the process identifier of the process with the memory leak to the leak process distribution module, and the leak process distribution module distributes the process identifier corresponding to the process with the memory leak to the memory reclamation module.

[0126] The scheduling module reports the memory reclamation status and secondary reclamation list of processes with memory leaks, sent by the memory reclamation module, to the server. The log processing module generates logs and reports them to the server when the memory reclamation module reclaims leaked memory.

[0127] The kernel layer is the layer between hardware and software. The kernel layer includes at least: a memory reclamation module, a page fault handling module, a page management module, an object management module, an input / output (I / O) scheduler, etc. The memory reclamation module includes a memory daemon module, a leaked page statistics reporting module, and a leaked page swapping management module.

[0128] The memory reclamation module is used to reclaim memory data from processes with memory leaks. The memory daemon module is used to initiate memory data reclamation when system memory is insufficient.

[0129] In this embodiment of the application, after the memory reclamation module receives the process identifier corresponding to the process with memory leakage sent by the leak process distribution module, the memory daemon process module begins to reclaim the memory data of the process with memory leakage.

[0130] The page fault handling module is used to manage the memory swapping process. The page management module is used to locate the memory segment corresponding to the memory to be swapped in. The I / O scheduler is used to read the memory segment corresponding to the memory to be swapped in. The object management module is used to decompress the memory segment corresponding to the memory to be swapped in.

[0131] In this embodiment, when the page fault handling module initiates memory swapping, the page management module locates the memory segment to be swapped into memory, and the I / O scheduler reads the memory segment located by the page management module. Then, the object management module decompresses the memory segment read by the I / O scheduler and finally swaps it into the system's memory.

[0132] The Leaked Page Statistics and Reporting Module is used to collect statistics on pages with memory leaks and report them.

[0133] In this embodiment, when the memory daemon module swaps out the memory data corresponding to a process with a memory leak to a temporary storage area, the leak page statistics and reporting module can record a memory address table. This table is used to record the correspondence between the memory address before the data was swapped out and the memory address swapped into the temporary storage area. The temporary storage area is a storage area other than main memory, such as swap or external storage.

[0134] The leaked page swapping management module is used to manage the swapping in and swapping out of pages with memory leaks.

[0135] All the technical solutions involved in the following embodiments can be implemented in the electronic device 100 having the above-described hardware structure and software architecture. The following uses a mobile phone as an example to illustrate this solution.

[0136] When a phone boots up, the daemon process module starts along with the system, and the memory leak detection module starts along with the daemon process module. After the phone boots up, if the user launches an application, the application will request memory from the system, and the corresponding application process will also occupy memory. After an application requests memory, some applications may not release that memory even after it has finished using it or after entering the background, leading to memory leaks. Therefore, the memory leak detection module needs to detect the memory usage of the processes corresponding to the applications launched on the phone to determine whether there are any processes with memory leaks based on the detection results.

[0137] Understandably, during actual operation, mobile applications may have one process or multiple processes. When an application corresponds to one process, the memory leak detection module can determine whether the application has a memory leak based on the process's memory usage. When an application corresponds to multiple processes, the module can determine whether the applications to which those processes belong have memory leaks based on the memory usage of those processes. The memory leak detection module can determine that the entire application has a memory leak if any one of the multiple processes corresponding to an application experiences a memory leak.

[0138] In one possible scenario, if the memory leak detection module fails to detect any processes with memory leaks on the phone after one detection cycle, the module will proceed to the next detection cycle to continue detecting any processes with memory leaks on the phone.

[0139] In another possible scenario, after a detection cycle of the memory leak detection module, it identifies a process with a memory leak on the phone. In this case, the memory leak detection module sends the process identifier corresponding to the process with the memory leak to the leak process distribution module. After receiving the process identifier with the memory leak from the memory leak detection module, the leak process distribution module sends the process identifier to the memory daemon process module of the memory reclamation module.

[0140] For example, such as Figure 5 As shown in (a), assuming the memory leak detection module determines that application A has a memory leak, the memory leak detection module can send the process identifier corresponding to application A (e.g., process ID 1111, process name application A) to the leak process distribution module. Further, after receiving the process identifier of application A sent by the memory leak detection module, the leak process distribution module sends the process identifier to the memory daemon process module of the memory reclamation module.

[0141] In one possible implementation of this application, when the memory leak detection module determines whether a process with a memory leak exists in the mobile phone, it can first identify suspicious processes that may have a memory leak, and then determine whether the suspicious process has a memory leak based on the memory information of the suspicious processes. The specific implementation process is as follows.

[0142] In this embodiment, after obtaining the memory information of a process, the memory leak detection module determines the process's memory increase rate and / or total memory usage based on the process's memory information. Furthermore, the memory leak detection module determines whether the process is a suspicious process based on the process's memory increase rate and / or total memory usage, including but not limited to the following three methods:

[0143] In one possible approach, the memory leak detection module determines, based on the process's memory information, that the process's memory increase rate exceeds a first threshold. In this case, it indicates that the process has requested a large amount of memory in a short period of time, suggesting a potential memory leak, and therefore the process is added to a graylist.

[0144] In another possible approach, the memory leak detection module determines, based on the process's memory information, that the process's total memory usage exceeds a threshold (e.g., the process's memory usage exceeds a preset threshold, or the process's memory usage as a percentage of system memory exceeds a preset percentage). In this case, it indicates that the process is consuming too much system memory, suggesting a potential memory leak, and therefore the process is added to a graylist.

[0145] In another possible approach, the memory leak detection module determines both the process's memory increase rate and total memory usage based on the process's memory information. If the process's memory increase rate exceeds a first rate threshold and its total memory usage exceeds a usage threshold, it indicates that the process has requested a large amount of memory in a short period, and its total system memory usage is excessive. Therefore, the process is considered to have a potential memory leak and is added to the graylist.

[0146] It should be explained that the aforementioned first rate threshold and occupancy threshold can be set according to the process's memory usage, or they can be built-in system values, which are not limited here.

[0147] In this embodiment, when the memory leak detection module determines whether a process is a suspicious process based on its memory information, it can determine whether the process is a suspicious process based on at least one of the following: the process's memory increase rate, total memory usage, and whether the process's memory has not been accessed for a long time. For example, if the memory leak detection module determines based on the process's memory information that the process has not been accessed within a preset time period, then the process can be determined to be a suspicious process.

[0148] In this embodiment of the application, when the memory leak detection module determines whether a suspicious process has a memory leak based on the collected memory information of the suspicious process, it includes, but is not limited to, the following six situations.

[0149] In the first scenario, if the average memory increase rate of the suspicious process is greater than or equal to the second rate threshold, it indicates that the suspicious process has been continuously requesting a large amount of memory in a short period of time, confirming a memory leak in the suspicious process. In this case, the system can return the first flag (e.g., return 1). As an example, assuming the memory leak detection module currently calculates an average memory increase rate of more than 500KB / s for the suspicious process, it determines that the suspicious process has a memory leak, and the system returns 1.

[0150] In this embodiment, after the memory leak detection module determines whether a suspicious process has a memory leak, it returns a corresponding identifier. The electronic device's system can then determine whether an application currently has a memory leak based on the identifier returned by the memory leak detection module. For example, if the memory leak detection module determines that a suspicious process has a memory leak and returns a first identifier, the system can determine whether the application of the electronic device currently has a memory leak based on the first identifier.

[0151] In the second scenario, if the average memory increase rate of the suspicious process is less than the second rate threshold, and the number of calculated memory increase rates is greater than the first rate threshold, and the last calculated consecutive preset number of memory increase rates are all greater than the third rate threshold (where the third rate threshold is less than the second rate threshold), this indicates that although the suspicious process has not requested a large amount of memory in a short period, it is continuously requesting memory from the system, and the amount of memory requested is continuously increasing. This also confirms that the suspicious process has a memory leak. In this case, the system also returns the first flag (e.g., returns 1). For example, the second rate threshold is set to 500KB / s, and the third rate threshold is set to 30KB / s.

[0152] As an example, suppose the memory leak detection module calculates the average memory increase rate of the suspicious process to be less than 500KB / s, and the rate calculation is performed 10 times or more, and the memory increase rate of the last 4 consecutive calculations is greater than 30KB / s. Then, it is determined that the suspicious process has a memory leak, and the system returns 1.

[0153] In the third scenario, if the average memory increase rate of the suspicious process is less than the second rate threshold, and the number of calculated memory increase rates is greater than the first rate threshold, and one of the last calculated consecutive preset number of memory increase rates is less than the third rate threshold, and the total memory usage is greater than the memory threshold, then this indicates that although the suspicious process did not request a large amount of memory in a short period of time, it continuously requested memory from the system, and the total amount of memory requested was large. This also confirms that the suspicious process has a memory leak. In this case, the system can return the first flag (e.g., return 1).

[0154] As an example, suppose the memory leak detection module calculates that the average memory increase rate of the suspicious process is less than 500KB / s, and the rate calculation is performed 10 times or more. In the last four consecutive calculations, there is a memory increase rate of less than 30KB / s, and the total memory usage exceeds 200MB. Then, it is determined that the suspicious process has a memory leak, and the system returns 1.

[0155] In the fourth scenario, if the average memory increase rate of the suspicious process is less than the second rate threshold, and the number of calculated memory increase rates is greater than the first rate threshold, and one of the last calculated consecutive preset number of memory increase rates is less than the third rate threshold, and the total memory usage is less than or equal to the memory threshold, then this indicates that the suspicious process did not request a large amount of memory in a short period of time. Although the suspicious process continuously requests memory from the system, the memory requested by the suspicious process occupies a small amount of the total system memory, confirming that the suspicious process does not have a memory leak. In this case, the system can return the second flag (e.g., return 2).

[0156] As an example, suppose the average memory increase rate of the suspected process currently calculated by the memory leak detection module is less than 500KB / s, and the rate calculation has been performed 10 times or more, and one of the last four consecutive memory increase rate calculations is less than 30KB / s, and the total memory usage does not exceed 200MB, then it is determined that the suspected process does not have a memory leak, and the system returns 2.

[0157] In the fifth scenario, if the number of cycles during which the memory leak handling module collects memory information from suspicious processes is less than the second threshold, then the memory leak detection module has not obtained sufficient memory information from suspicious processes. This indicates insufficient data, making it impossible to determine if a suspicious process has a memory leak. In this case, the system can return a third flag (e.g., 0). For example, if the memory leak handling module collects memory information from suspicious processes less than 5 times, it considers the data insufficient.

[0158] In the sixth scenario, if the memory leak detection module determines that the amount of memory information collected from suspicious processes is less than the number of collection cycles, then the memory leak handling module has not obtained sufficient memory information from the suspicious processes. Therefore, it can be determined that the data is insufficient and it is impossible to determine whether a suspicious process has a memory leak. In this case, the system can return a third flag (e.g., return 0).

[0159] It should be noted that the values ​​of the second rate threshold, third rate threshold, first number threshold, second number threshold, and memory threshold in the above examples are merely illustrative descriptions and can be set to different values ​​depending on the suspected process. That is, the second rate threshold, third rate threshold, first number threshold, second number threshold, and memory threshold may be the same or different for different processes, and this is not limited here. For example, if the suspected process is the process of application E, the second rate threshold can be set to 500KB / s, the third rate threshold to 30KB / s, the first number threshold to 10 times, the second number threshold to 4 times, and the memory threshold to 200MB; if the suspected process is the process of application B, the second rate threshold can be set to 400KB / s, the third rate threshold to 25KB / s, the first number threshold to 8 times, the second number threshold to 4 times, and the memory threshold to 180MB.

[0160] It should be noted that the memory leak detection method in this application embodiment is not limited to the above implementation process, and any method that can be used to detect memory leaks can be applied to this application embodiment.

[0161] After the memory leak detection module identifies a process with a memory leak on the phone, it sends the process identifier corresponding to the process with the memory leak to the leak process distribution module. Upon receiving the process identifier from the memory leak detection module, the leak process distribution module sends it to the memory guardian module of the memory reclamation module, enabling the memory guardian module to recover the memory data of the process with the memory leak.

[0162] It's important to explain that when the memory leak detection module detects memory leaks in multiple processes on the phone, the memory guardian module can recover the memory data of the processes with memory leaks based on the order in which they were detected. For example, after the memory leak detection module detects a memory leak in process 1, the memory guardian module begins to reclaim the memory data of process 1. During this reclamation process, the memory leak detection module detects a memory leak in process 2. Once the memory data reclamation from process 1 meets the required amount of memory data to be swapped out, the memory guardian module begins to reclaim the memory data of process 2, continuing this process until the memory data reclamation from process 2 meets the required amount of memory data to be swapped out.

[0163] When the memory daemon module begins recovering memory data from a process with a memory leak, it determines the amount of memory data to be swapped out based on the process's memory leak rate and / or the process's current memory usage. Then, the memory daemon module performs batch swapping out of the process's memory data in units of memory per swap, until the swapped-out amount reaches the amount of memory data to be swapped out. This memory swapping process then ends. For example, the amount of memory data to be swapped out can be the minimum value between the process leak rate * 300 and 1 / 10 * the process's current memory usage.

[0164] It is understandable that when the memory daemon module determines the amount of memory data to be swapped out for a process, it considers the process's memory leak rate and / or the process's current memory usage. Specifically, when the memory daemon module determines that the process's memory leak rate is high or the process's current memory usage is high, more memory data can be swapped out, meaning the amount of memory data to be swapped out is larger. This not only solves the process's memory leak problem but also ensures that the process retains some available memory for application use. After the memory leak detection module detects a process with a memory leak, the memory daemon module needs to determine whether memory reclamation is necessary based on whether the system's available storage exceeds a threshold of 1. This threshold of 1 can be set based on the system's total available storage and is not limited here. For example, if phone A has a large total available storage, a larger threshold of 1 can be set; if phone B has a small total available storage, a smaller threshold of 1 can be set. For example, ... Figure 6 As shown, when the memory daemon module performs memory recovery (e.g., memory reclamation) on the memory of a process with a memory leak, it includes, but is not limited to, the following situations.

[0165] In the first scenario, the memory daemon module determines that the system's available storage is greater than a threshold of 1. This threshold can be a first storage threshold, meaning that a large available storage level will not affect the phone's performance. In this case, the memory daemon module does not need to perform memory dumping for the processes with memory leaks. Instead, it sends the status of not having reclaimed the process's memory data to the scheduling module. The scheduling module then sends this status, along with a secondary reclamation list, to the server, allowing the server to track whether the system has reclaimed the process's memory data. The secondary reclamation list is a linked list of memory blocks belonging to processes with memory leaks, obtained through native Linux interfaces (such as ` / proc / pid / smaps`).

[0166] In the second scenario, the memory daemon module determines that the system's available storage is less than or equal to a threshold of 1, meaning that the system's available storage is low, which will affect the phone's performance. In this case, the memory daemon module needs to transfer the memory data corresponding to the processes with memory leaks.

[0167] However, in some embodiments, the memory daemon module determines that the current process's memory usage exceeds a threshold of 2, where threshold 2 can be a usage threshold, indicating that the process is being called too frequently. In this case, the memory daemon module temporarily refrains from reclaiming the process's memory data and sends the status of not reclaiming the process's memory data to the scheduling module. Upon receiving the status from the memory daemon module indicating that the process's memory data has not been reclaimed, the scheduling module sends the status of not reclaiming the process's memory data and the secondary reclamation list to the server side, ending the memory recovery process. Here, the memory usage refers to the frequency at which the page corresponding to the process is called. The memory usage can also reflect the data thrashing rate, meaning that the process's memory data is still being accessed intermittently. In this case, the memory daemon module temporarily refrains from reclaiming the process's memory data to improve the performance of the electronic device.

[0168] In other embodiments, the memory daemon module determines that the current process's occupancy rate is less than or equal to threshold 2, and that the available storage in the temporary storage area is less than or equal to threshold 3. In this case, the memory daemon module determines that the temporary storage area does not have sufficient storage space to store the memory data to be reclaimed. Therefore, the memory daemon module temporarily does not reclaim the process's memory data, and it also sends the status of not reclaiming the process's memory data to the scheduling module. After receiving the status of not reclaiming the process's memory data from the memory daemon module, the scheduling module sends the status of not reclaiming the process's memory data and the secondary reclamation list to the server side, so that the server side can count whether the system has reclaimed the process's memory data.

[0169] The temporary storage area refers to the storage space used to store the memory data of processes with memory leaks. The memory daemon module can swap the memory data of processes with memory leaks to the temporary storage area. In this embodiment, the temporary storage area can be a storage area other than main memory, such as a swap partition or external storage, and is not limited thereto. Threshold 3 can be a second storage threshold, i.e., a low threshold value for the available storage in the temporary storage area. For example, threshold 3 can be SWP_TOTAL*1 / 10, where SWP_TOTAL is min(total available memory size of the system * 1 / 12, current available external storage size of the system * 1 / 10).

[0170] It should be explained that the values ​​of threshold 2 and threshold 3 mentioned above are not limited in this application. For example, different thresholds 2 can be set when different processes have memory leaks.

[0171] In some embodiments, after the memory daemon module determines that the current process's occupancy rate is less than or equal to threshold 2, and further determines that the available storage in the temporary storage area is greater than threshold 3, the memory daemon module begins to perform a memory swapping operation (e.g., swapping anonymous pages of processes with memory leaks). When swapping memory data, the memory daemon module generates or updates a secondary garbage collection list, and terminates the memory recovery process when the memory data is swapped out. Here, anonymous pages refer to heap memory dynamically allocated by the application; anonymous pages are likely to be accessed again and cannot be directly released.

[0172] In some embodiments of this application, when the memory daemon module performs memory swapping operations, it can transfer the anonymous pages of processes with memory leaks to a temporary storage area. When swapping out anonymous pages, the memory daemon module generates or updates the secondary garbage collection list. Upon determining that an anonymous page has been swapped out, the memory daemon module terminates the memory recovery process. The following describes the process in conjunction with... Figure 7 This section provides a detailed explanation of how the memory daemon module transfers anonymous pages to a temporary storage area.

[0173] For example, such as Figure 7 As shown, after the memory reclamation module receives the process identifier of the memory leak from the memory leak detection module, the memory daemon module is awakened. The memory daemon module first determines whether the available storage of the system is less than a threshold of 4 to determine whether the anonymous pages of the process with the memory leak need to be dumped. If the memory daemon module determines that the available storage of the system is less than the threshold of 4, it indicates that the available storage of the system is small, and the memory daemon module begins to reclaim the anonymous pages. When the memory daemon module determines that the available storage of the system is less than the threshold of 4, it determines the size of the available storage in the temporary storage area.

[0174] In one possible scenario, if the memory daemon module determines that the available storage in the temporary storage area is greater than threshold 5, then the temporary storage area has sufficient space to store anonymous pages, and the memory daemon module begins to reclaim anonymous pages. If, during the transfer of anonymous pages, the memory daemon module determines that the available storage in the temporary storage area is greater than threshold 6 (meaning there is insufficient storage space in the temporary storage area), then the memory daemon module transfers the data from that temporary storage area to the memory buffer. Then, if the memory daemon module determines that the available storage in the system is less than threshold 4, the anonymous page swapping process ends.

[0175] In some embodiments, the temporary storage area can be a compressed memory area (e.g., zRAM). During the process of the memory daemon module reclaiming anonymous pages, if the memory daemon module determines that the available storage in zRAM is greater than a threshold of 6, meaning there is insufficient storage space in zRAM to store anonymous pages, the memory daemon module can transfer the data stored in zRAM to a memory buffer (e.g., eswap). zRAM is a feature of the Linux kernel that provides virtual memory compression. zRAM can use memory to replace hard disks to provide swap space for the system.

[0176] In another possible scenario, the memory daemon module determines that the available storage in the temporary storage area is less than or equal to the threshold of 5. In this case, it indicates that the temporary storage area does not have enough storage space to store the anonymous page, and the memory daemon module will not reclaim the anonymous page temporarily. At this point, the memory daemon module can report the status of the unreclaimed memory data for this process to the scheduling module.

[0177] When the memory daemon module determines that the available storage in the temporary storage area is less than or equal to threshold 5, or the available storage in the system is greater than or equal to threshold 3, the memory daemon module will temporarily not reclaim the anonymous page. The memory daemon module can report this temporary non-reclaimment status to the scheduling module. The scheduling module will then report this status to the server side, allowing the server to track whether anonymous pages have been reclaimed.

[0178] It should be explained that when the memory daemon module swaps out the anonymous pages of a process with a memory leak, it does not swap out all the anonymous pages corresponding to that process. In the embodiments of this application, the memory daemon module determines the anonymous pages of the process to be swapped out in the following ways, including but not limited to the following.

[0179] In the first scenario, the memory daemon module can prioritize releasing pages that haven't been accessed within a preset timeframe and are located in the secondary garbage collection list. This prioritizes releasing pages that haven't been accessed for a long time, improving the available memory in the electronic device. For example, assuming the secondary garbage collection list includes page 1, page 2, and page 3, and the memory daemon module determines that page 2 hasn't been accessed for a long time, it will prioritize swapping out page 2 when swapping out anonymous pages in the process, thus freeing up memory in the electronic device.

[0180] In the second scenario, if the memory daemon module determines that there are no pages in the secondary reclamation list that have not been accessed, it will release the page that was first added to the secondary reclamation list. For example, assuming the secondary reclamation list includes page 1, page 2, and page 3, and the memory daemon module determines that page 1 was added to the secondary reclamation list first, when swapping out anonymous pages of a process, the memory daemon module will prioritize swapping out page 1 to release the memory of the electronic device.

[0181] In the third scenario, the memory daemon module can prioritize releasing pages that are not accessed by multiple processes simultaneously, but only by the process with the memory leak. For example, assuming the secondary reclamation list includes page 1, page 2, and page 3, the memory daemon module determines that page 1 is only accessed by the process with the memory leak and not by other processes. The memory daemon module will prioritize swapping out page 1 to release the memory of the electronic device.

[0182] Understandably, the memory daemon module can determine the anonymous pages to be swapped out based on their priority order. Specifically, the priority order is as follows: anonymous pages that have not been called within a preset time period have a higher priority than the anonymous pages first added to the secondary recycling list; and anonymous pages first added to the secondary recycling list have a higher priority than anonymous pages that have not been called by multiple processes simultaneously.

[0183] In some embodiments, after the memory daemon module swaps out anonymous pages with memory leaks to the Swap partition in the temporary storage area, there may be a situation where the storage space of the Swap partition is insufficient. In this case, the memory daemon module can perform a secondary reclamation, that is, the memory daemon module can release the memory data in the Swap partition to secondary storage.

[0184] In this embodiment, when the memory daemon module reclaims memory data from a process with a memory leak, after receiving the process identifier sent by the leaking process distribution module, the memory daemon module obtains the memory information corresponding to the process with the memory leak based on a native Linux interface (such as the / proc / pid / smaps interface). Then, based on the memory information of the process with the memory leak, the memory daemon module swaps out the memory data corresponding to that process to external storage. The memory information corresponding to the process may include the process's memory usage, memory header, memory address, and memory access count. For example, memory usage includes the resident set size (RSS) and / or ION memory. RSS refers to the memory space allocated to the corresponding process after request, including shared libraries, and can be considered as all the memory space actually occupied by the corresponding process. ION memory refers to shared memory located in the swap partition, mainly used for fast data interaction between applications, and is a memory management mode unique to Android.

[0185] The following example illustrates how to obtain memory information for processes with memory leaks using native Linux interfaces (such as / proc / pid / smaps).

[0186] For example, ` / proc / pid / smaps` is an interface for understanding process memory information. By calling ` / proc / pid / smaps`, you can query the memory information of the process corresponding to a process address (PID). Figure 8 As an example, Figure 8 The image shows the memory information for the process with PID 1. RSS refers to the current memory size occupied by the system for process PID 1, which is 276KB; Size refers to the virtual memory space size, which is 1388KB; the memory header is 0006c000; the number of memory accesses is 14; the memory addresses are 556bde7000-556bf42000, etc. It needs to be explained that... Figure 8 The image only shows a portion of the contents of the / proc / smaps file. The full contents are based on the memory information of the process obtained by actually calling the / proc / smaps interface, and are not limited here.

[0187] After obtaining the memory address corresponding to the process with memory leaks through the aforementioned interface, the memory daemon module swaps out the memory data stored at that address to a temporary storage area. In this way, the memory daemon module swaps out the memory data of processes with memory leaks in electronic devices, resolving the problem of insufficient memory or lag caused by memory leaks in application processes, and improving the performance of electronic devices.

[0188] For example, such as Figure 5 As shown in (b), after the memory leak detection module detects a memory leak in application A, it sends the process ID and process name of application A to the memory daemon module. After the memory daemon module starts, it uses the received process ID and process name of application A, and according to a native Linux interface (such as / proc / pid / smaps), swaps out the memory data corresponding to the process with the memory leak in application A to a temporary storage area.

[0189] When the memory daemon module swaps out the memory data corresponding to a process with a memory leak to the temporary storage area, it can determine whether memory compression is needed based on the available storage space in the temporary storage area. In other words, if the available storage space in the phone's temporary storage area is large enough that memory compression is unnecessary, then memory compression is not required. However, if the available storage space in the phone's temporary storage area is small, memory compression is necessary to conserve storage space. Therefore, whether memory compression is needed when the memory daemon module swaps out the memory data corresponding to a process with a memory leak to the temporary storage area can be determined based on the available storage space in the temporary storage area, and is not limited here.

[0190] In some embodiments, when the memory daemon module moves the memory data corresponding to a process with a memory leak to a temporary storage area, the leaked page statistics reporting module can also record the correspondence between the memory address before the data was moved and the memory address in the temporary storage area. For example, the leaked page statistics reporting module can record this correspondence using a memory address table. Thus, by storing the memory addresses before and after the data swap using the memory address table recorded by the leaked page statistics reporting module, the corresponding memory address can be retrieved from the memory address table when the memory data stored in the temporary storage area is needed again.

[0191] For example, such as Figure 5As shown in (c), when the memory daemon module swaps out the memory data corresponding to the process with a memory leak in application A to secondary storage, the leak page statistics and reporting module can record a memory address table. This table can be used to record the memory address before the data was swapped out and the memory address swapped to secondary storage. As shown in Table 1 below, assuming that the memory address of the process with process ID 1111 in application A before swapping out was 556bde7000-556bf42000, and the memory address of the process's memory data swapped out to secondary storage was 556bce3200-556be52100, a memory address table can be recorded to store the memory address before swapping out the memory data corresponding to the process with the memory leak and the memory address swapped out to the temporary storage area.

[0192] Table 1

[0193]

[0194] In some embodiments of this application, before the memory daemon module determines whether to transfer the memory data of a process with a memory leak to a temporary storage area, the phone can prompt the user whether to transfer the memory data corresponding to that process out of memory. This improves the phone's performance by allowing the user to determine whether to transfer the memory data based on the prompt. For example, the phone's display shows a prompt to alert the user that certain applications have memory leaks, and the user can actively instruct the phone to release the memory occupied by that application based on the prompt.

[0195] In some embodiments, see Figure 9A The phone can prompt the user, "Application A has a memory leak. Do you want to release the memory occupied by application A?" If the phone detects that the user has clicked the "Yes" button, it will move the memory data corresponding to the process of application A out of memory to avoid performance issues such as insufficient memory or lag.

[0196] In some embodiments of this application, after the memory daemon module determines that the memory data of a process with a memory leak has been moved to a temporary storage area, the phone can notify the user that the leaked memory data of certain applications has been moved out. This reminds the user that the application with the memory leak has been addressed, improving the phone's performance. For example, the phone's display shows a notification message to inform the user that the leaked memory of certain applications has been moved out.

[0197] like Figure 9B As shown, after the memory daemon module determines that the memory data of application A has a memory leak, it displays a prompt message on the phone's screen, such as... Figure 9B The message "Prompt: Leaked memory for application A has been moved out" is displayed to remind the user that the leaked memory for application A has been resolved.

[0198] In some embodiments of this application, after the memory daemon module determines that the processes of multiple applications on the mobile phone have memory leaks, the mobile phone can notify the user of the multiple applications with memory leaks by displaying prompt information, so that the user can set which applications' memory data among the multiple applications with memory leaks should be transferred.

[0199] Subsequently, when the memory daemon module determines that memory data swapped out to the temporary storage area will be accessed again, it can also swap the memory data stored in the temporary storage area back into memory. For example, if the memory daemon module determines that an application corresponding to a process with a memory leak needs to access the memory data swapped out to the temporary storage area again, it can swap the memory data stored in the temporary storage area back into memory. The following section combines... Figure 10 An exemplary description of the page loading process is provided.

[0200] For example, such as Figure 10 As shown, the page swapping process is controlled by the page error handling module. When the page management module locates the memory segment to be swapped into memory, it returns flag 1 to the page error handling module. Further, the I / O scheduler reads the memory segment located by the page management module and returns flag 2 to the page error handling module. Then, the object management module decompresses the memory segment read by the I / O scheduler and returns flag 3 to the page error handling module. Finally, the page error handling module swaps the decompressed memory segment into the current memory, completing the entire swapping process.

[0201] It needs to be explained that, Figure 10 The decompression of memory segments read by the I / O scheduler by the object management module is not a mandatory process. If the memory segment to be swapped out was not compressed during swapping in, the object management module does not need to decompress the memory segment when swapping it out.

[0202] For example, such as Figure 11 As shown, after the memory daemon module swaps out the memory data corresponding to the process with memory leaks in application A, when application A needs to access that memory data again, the page fault handling module reads the memory address of the swapped-out memory data from the memory address table recorded during memory swapping, and then swaps a portion of the application A's memory data stored in the temporary storage area back into memory. For example... Figure 11 As shown, since the storage space for the memory data swapped out in application A has been used by application B, the system needs to reallocate memory addresses for the memory data swapped in from the temporary storage area.

[0203] In summary, in this embodiment of the application, after the memory leak detection module determines that there is a memory leak in a process of the electronic device, the memory reclamation module reclaims the leaked memory of the process with the memory leak. Thus, by reclaiming the memory of the process with the memory leak, the problem of insufficient available memory of the electronic device is solved, and the performance of the electronic device is improved.

[0204] Compared to existing memory leak handling methods that directly release leaked memory, which can lead to application addressing errors when the leaked memory is accessed again, the memory leak handling method in this application moves the memory data of the process with memory leaks to a temporary storage area. When this memory data is accessed again, it is then swapped back into the temporary storage area. This prevents applications with memory leaks from failing to run properly and improves the performance of electronic devices.

[0205] like Figure 12 As shown in the illustration, this application discloses an electronic device, which can be the mobile phone described above. Specifically, the mobile phone may include: a touchscreen 1201, which includes a touch sensor 1206 and a display screen 1207; one or more processors 1202; a memory 1203; one or more application programs (not shown); and one or more computer programs 1204. These devices can be connected via one or more communication buses 1205. The one or more computer programs 1204 are stored in the memory 1203 and configured to be executed by the one or more processors 1202. The one or more computer programs 1204 include instructions that can be used to perform the relevant steps in the above embodiments.

[0206] It is understood that, in order to achieve the aforementioned functions, the aforementioned terminals and other devices include hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein, the embodiments of this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware 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 embodiments of this invention.

[0207] This application embodiment can divide the aforementioned terminal, etc., into functional modules according to the above method examples. For example, each function can be divided into its own functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division; in actual implementation, there may be other division methods.

[0208] When each functional module is divided according to its corresponding function, the above embodiments illustrate a possible composition of the electronic device, which may include a display unit, a transmission unit, and a processing unit. It should be noted that all relevant content regarding the steps in the above method embodiments can be referenced from the functional descriptions of the corresponding functional modules, and will not be repeated here.

[0209] This application also provides an electronic device, including one or more processors and one or more memories. The one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code, including computer instructions. When the one or more processors execute the computer instructions, the electronic device performs the aforementioned method steps to implement the memory leak handling method in the above embodiments.

[0210] Embodiments of this application also provide a computer-readable storage medium storing computer instructions. When the computer instructions are executed on an electronic device, the electronic device performs the aforementioned method steps to implement the memory leak handling method in the above embodiments.

[0211] The embodiments of this application also provide a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to implement the memory leak handling method executed by the electronic device in the above embodiments.

[0212] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component or module. The apparatus may include a connected processor and a memory. The memory is used to store computer execution instructions. When the apparatus is running, the processor can execute the computer execution instructions stored in the memory to enable the apparatus to perform the memory leak handling method executed by the electronic device in the above method embodiments.

[0213] In this embodiment, the electronic device, computer-readable storage medium, computer program product or device are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0214] Through the above description of the embodiments, those skilled in the art will clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device, and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0215] In the embodiments of this application, the functional units can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0216] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as flash memory, portable hard disk, read-only memory, random access memory, magnetic disk, or optical disk.

[0217] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A memory leak handling method, applied to an electronic device, the electronic device including at least one process, the at least one process including a first process, characterized in that, The method includes: If it is determined that the memory meets the first preset condition, then the memory data corresponding to the first process is obtained; the first preset condition includes the existence of a memory leak in the first process; Transfer the memory data corresponding to the first process to the temporary storage area; If the memory data corresponding to the first process is accessed, the memory address table is queried to obtain the second storage address of the memory data in the temporary storage area; wherein, the memory address table records the correspondence between the first storage address of the memory data in memory and the second storage address in the temporary storage area; after obtaining the memory data from the second storage address, the memory data is transferred to the storage area of ​​memory; Wherein, the temporary storage area is a storage area outside of the main memory; the step of transferring the memory data corresponding to the first process to the temporary storage area includes: Based on the memory leak rate and / or memory usage of the first process, the memory amount of the memory data corresponding to the first process is determined; wherein, the memory leak rate is determined based on the memory acquisition time and the corresponding memory usage; the memory data corresponding to the first process is transferred in units of memory until the amount of memory data corresponding to the first process stored in the temporary storage area is greater than or equal to the memory amount of the memory data.

2. The method according to claim 1, characterized in that, The condition of satisfying the first preset condition also includes that at least one of the following conditions is satisfied: the available storage of the system, the available storage of the temporary storage area, and the memory occupancy rate of the first process.

3. The method according to claim 2, characterized in that, The condition of satisfying the first preset condition also includes: The available storage capacity of the system is less than or equal to a first storage capacity threshold.

4. The method according to claim 2, characterized in that, The condition of satisfying the first preset condition also includes: The available storage capacity of the temporary storage area is greater than the second storage capacity threshold and / or the occupancy rate is less than the occupancy rate threshold.

5. The method according to claim 2, characterized in that, The method further includes: If the available storage of the system is greater than the first storage threshold, or the available storage of the temporary storage area is less than or equal to the second storage threshold, or the occupancy rate is greater than or equal to the occupancy rate threshold, then the status of not transferring the memory data corresponding to the first process is reported.

6. The method according to any one of claims 1-5, characterized in that, Before determining the amount of memory data corresponding to the first process based on the memory leak rate and / or memory usage of the first process, the method further includes: Obtain the memory information of the first process; wherein the memory information includes the memory acquisition time and the corresponding memory usage.

7. The method according to any one of claims 1-5, characterized in that, The memory data includes anonymous pages, and the step of transferring the memory data corresponding to the first process to the temporary storage area includes: According to the priority order of the anonymous pages, the anonymous pages are transferred to the temporary storage area; wherein, the priority order is that the anonymous page that has not been called within a preset time period has a higher priority than the anonymous page that was first added to the secondary recycling list, and the anonymous page that was first added to the secondary recycling list has a higher priority than the anonymous page that has not been called by multiple processes at the same time.

8. The method according to any one of claims 1-5, characterized in that, Before transferring the memory data corresponding to the first process to the temporary storage area, the method further includes: Compress the memory data corresponding to the first process.

9. The method according to claim 8, characterized in that, After obtaining the memory data from the second storage address, the step of transferring the memory data to the storage area of ​​the memory includes: The memory data obtained from the second storage address is decompressed; The decompressed memory data is then transferred to the memory's storage area.

10. The method according to any one of claims 1-5, characterized in that, After transferring the memory data corresponding to the first process to the temporary storage area, the method further includes: Obtain the available storage capacity of the temporary storage area; If the available storage capacity of the temporary storage area is less than or equal to the third storage capacity threshold, the memory data stored in the temporary storage area will be transferred to the buffer.

11. The method according to any one of claims 1-5, characterized in that, Before transferring the memory data corresponding to the first process to the temporary storage area, the method further includes: Display a prompt message; wherein the prompt message is used to prompt the user whether to move the memory data corresponding to the first process out of memory.

12. The method according to any one of claims 1-5, characterized in that, The at least one process further includes a second process, and the determination that the memory satisfies a first preset condition includes the first process having a memory leak, including: Obtain the first memory information corresponding to the first process and the second memory information corresponding to the second process; Based on the first memory information corresponding to the first process and the second memory information corresponding to the second process, it is determined that the first process meets the second preset condition and the second process does not meet the second preset condition. Obtain the third memory information corresponding to the first process; Based on the third memory information corresponding to the first process, it is determined that the first process has a memory leak.

13. The method according to claim 12, characterized in that, The first memory information includes the first memory acquisition time and the corresponding first memory usage. Determining that the first process meets the second preset condition includes: Based on the first memory increase rate and / or the first total memory usage of the first process, it is determined that the first process meets the second preset condition; wherein, the first memory increase rate is determined based on at least two first memory acquisition times of the first process and the corresponding first memory usage; the first total memory usage is determined based on the first memory usage.

14. The method according to claim 13, characterized in that, The step of determining that the first process meets the second preset condition based on the first memory increase rate and / or the first total memory usage of the first process includes: If the first memory increase rate of the first process is greater than the first rate threshold and / or the total memory usage of the first process is greater than the usage threshold, then the first process is determined to meet the second preset condition.

15. The method according to claim 12, characterized in that, The third memory information includes the second memory acquisition time and the corresponding second memory usage. Determining that the first process has a memory leak based on the third memory information corresponding to the first process includes: A memory leak is determined in the first process based on at least one of the second memory increase rate, the average memory increase rate, and the second total memory usage; wherein the second memory increase rate is determined based on at least two second memory acquisition times of the first process and the corresponding second memory usage; the average memory increase rate is determined based on at least one second memory increase rate; and the second total memory usage is determined based on the second memory usage.

16. The method according to claim 15, characterized in that, The step of determining that the first process has a memory leak based on at least one of the second memory increase rate, the average memory increase rate, and the second total memory usage includes: If the average memory increase rate of the first process is greater than or equal to the second rate threshold, then it is determined that the first process has a memory leak.

17. The method according to claim 15, characterized in that, The step of determining that the first process has a memory leak based on at least one of the second memory increase rate, the average memory increase rate, and the second total memory usage of the first process further includes: If the average memory increase rate of the first process is less than the second rate threshold, and the number of second memory increase rates is greater than the first number threshold, and a preset number of consecutive second memory increase rates are greater than the third rate threshold, then it is determined that the first process has a memory leak; wherein the third rate threshold is less than the second rate threshold.

18. The method according to claim 15, characterized in that, The step of determining that the first process has a memory leak based on at least one of the second memory increase rate, the average memory increase rate, and the second total memory usage of the first process further includes: If the average memory increase rate of the first process is less than the second rate threshold, and the number of second memory increase rates is greater than the first number threshold, and at least one of the consecutive preset number of second memory increase rates is less than the third rate threshold, and the total second memory usage is greater than the memory threshold, then it is determined that the first process has a memory leak.

19. An electronic device, characterized in that, include: One or more processors; Memory; The memory stores one or more computer programs, the one or more computer programs including instructions that, when executed by the electronic device, cause the electronic device to perform the memory leak handling method as described in any one of claims 1-18.

20. A computer-readable storage medium storing instructions, characterized in that, When the instructions are executed on an electronic device, the electronic device causes the electronic device to perform the memory leak handling method as described in any one of claims 1-18.

21. A computer program product, characterized in that, The computer program product includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the memory leak handling method as described in any one of claims 1-18.

Citation Information

Patent Citations

  • Memory dump method and device, and electronic equipment

    CN111638952A

  • Memory recovery method, device, electronic equipment and computer readable storage medium

    CN111966492A

  • Memory leak detection method, device and equipment

    CN112214394A

  • Memory leak detection

    US9760464B1