Memory leak detection method, electronic device and storage medium

By creating a target child process in the application process to obtain the Java object reference relationship of the Java heap, and identifying memory leaks in combination with memory exception conditions, the stability and security issues of Java heap memory leak detection are solved, and the effect of timely correcting memory leaks is achieved.

CN118484377BActive Publication Date: 2025-03-11HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311806444.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-22
Publication Date
2025-03-11
Estimated Expiration
2043-12-22

AI Technical Summary

Technical Problem

The existing technology is difficult to effectively detect and solve the memory leak problem in the Java heap, resulting in the continuous consumption of memory during long-term running of the application, which may lead to low memory and crashes.

Method used

By creating a target child process in the application process, using the child process to obtain the Java object reference relationship of the Java heap, determine the Java object in the running state of the memory, and identify the memory leaked object based on the set memory exception conditions.

Benefits of technology

This method can effectively reduce performance overhead, isolate target child processes and other threads of application processes, ensure the stability and security of memory leak detection, and promptly identify and correct memory leak problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118484377B_ABST
    Figure CN118484377B_ABST
Patent Text Reader

Abstract

The present application discloses a memory leak detection method, an electronic device and a storage medium, which relate to the field of memory management technology and are used to provide a memory leak detection solution to ensure the stability and security of memory management. The method comprises: in response to the memory of a Java heap being greater than a first memory threshold, based on a target subprocess in an application process, obtaining a Java object reference relationship of the Java heap; based on the Java object reference relationship, determining at least one Java object in the Java heap whose memory is in a running state; and in the at least one Java object, determining that a Java object that meets a memory exception condition is a Java object with a memory leak.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of memory management technology, and in particular to a memory leak detection method, an electronic device, and a storage medium. Background Art

[0002] In the field of memory management technology, memory leak refers to the situation where an application fails to release memory that is no longer in use due to negligence or error. In this way, when the application runs for a long time, the memory will be continuously consumed and eventually lead to low memory or even crash. Therefore, the detection of memory leaks is very important. Summary of the invention

[0003] The present application provides a memory leak detection method, an electronic device and a storage medium, which are used to provide a memory leak detection solution to ensure the stability and security of memory management.

[0004] In order to achieve the above objectives, this application adopts the following technical solutions:

[0005] In a first aspect, a memory leak detection method is provided, the method comprising:

[0006] In response to the memory of the Java heap being greater than the first memory threshold, the Java object reference relationship of the Java heap is obtained based on the target subprocess in the application process. In other words, the process of obtaining the Java object reference relationship of the Java heap is performed using the target subprocess in the application process (such as a newly constructed subprocess).

[0007] In this way, the operation of obtaining the Java object reference relationship is completed in the target child process of the application process. On the one hand, the target child process will inherit the data resources of the parent process (that is, the application process), thereby effectively reducing the performance overhead. On the other hand, it can effectively isolate the target child process from other threads in the application process, thereby avoiding the target child process from affecting other threads in the application process, thereby ensuring the stability of memory leak detection.

[0008] After obtaining the Java object reference relationship of the Java heap, at least one Java object in the Java heap whose memory is in a running state is determined based on the Java object reference relationship. The at least one Java object in the running state indicates that the at least one Java object is still being used, which means that the at least one Java object is a Java object that has not been actively released, that is, these Java objects in the running state are Java objects that may have memory leaks.

[0009] Furthermore, in the at least one Java object, a Java object that satisfies the memory exception condition is determined as a Java object with a memory leak. By setting the memory exception condition, the Java object with an exception is determined by using the memory exception condition among the Java objects that may have a memory leak, thereby determining the Java object with a memory leak.

[0010] In the above technical solution, when the memory of the Java heap is greater than the first memory threshold, the target subprocess in the application process is used to execute the process of obtaining the Java object reference relationship of the Java heap. In this way, the operation of obtaining the Java object reference relationship is completed in the target subprocess of the application process. On the one hand, the target subprocess will inherit the data resources of the parent process (i.e., the application process), thereby effectively reducing the performance overhead. On the other hand, the target subprocess can be effectively isolated from other threads in the application process, thereby avoiding the target subprocess from affecting other threads in the application process, thereby ensuring the stability of memory leak detection. Moreover, based on the Java object reference relationship, at least one Java object in the running state of the memory is determined, and the Java object that may have a memory leak is determined. Furthermore, by setting a memory exception condition, in the Java object that may have a memory leak, the memory exception condition is used to determine the abnormal Java object, thereby determining the Java object with a memory leak. In this way, a memory leak detection solution is provided, which can ensure the stability and security of memory management.

[0011] In a possible implementation manner of the first aspect, the application process includes a log monitoring thread, and the log monitoring thread includes the target subprocess.

[0012] Accordingly, based on the target subprocess in the application process, the Java object reference relationship of the Java heap is obtained, including:

[0013] Based on the signal processing function of the public signal, the target subprocess in the log monitoring thread is triggered, and the Java object reference relationship of the Java heap is obtained from the log file of the Java heap.

[0014] In this way, a signal processing function of a public signal is introduced to trigger the acquisition of the Java object reference relationship of the Java heap. Since the public signal is a signal used to achieve mutual exclusion between different processes or different threads in a process, the signal processing function based on the public signal can ensure that the process of obtaining the Java object reference relationship of the Java heap is executed only based on one or a group of processes (or threads), which can effectively avoid the current process from affecting other processes (or threads). Furthermore, through the target child process in the log monitoring thread, the Java object reference relationship of the Java heap is obtained from the log file of the Java heap. In this way, a lightweight solution for obtaining Java object reference relationships is provided.

[0015] In another possible implementation manner of the first aspect, before triggering the target subprocess in the log listening thread based on the signal processing function of the public signal, the method further includes:

[0016] Based on the signal processing function of the private signal, the signal processing function of the public signal is reset to a preset signal processing function, and the preset signal processing function is used to trigger the target subprocess in the log monitoring thread.

[0017] In this possible implementation method, when it is detected that the memory of the Java heap is greater than the first memory threshold, the signal processing function of the public signal is first reset to a preset signal processing function based on the signal processing function of the private signal, ensuring that the signal processing function of the public signal is the preset signal processing function, thereby avoiding the problem of memory leak detection failure due to an incorrect signal processing function, and effectively improving the stability of memory leak detection.

[0018] In another possible implementation of the first aspect, the Java object reference relationship includes: a reference relationship of multiple dynamic Java objects. It should be noted that since memory leaks are usually dynamic memory leaks based on the Java heap, obtaining the reference relationship of multiple dynamic Java objects is helpful for subsequent memory leak detection.

[0019] In another possible implementation of the first aspect, the Java object reference relationship is represented by a tree diagram;

[0020] Determining at least one Java object in a running state in memory of the Java heap based on the Java object reference relationship includes:

[0021] In the Java object reference relationship, at least one Java object reached by taking the Java object corresponding to the root node as a starting point is determined as at least one Java object in the Java heap memory in a running state.

[0022] In this possible implementation, a method for determining a Java object in a running state based on a Java object reference relationship is provided. In this way, the Java object in a running state can be determined quickly and efficiently, thereby improving the efficiency of determining the Java object in a running state.

[0023] In another possible implementation manner of the first aspect, the memory exception condition includes at least one of the following conditions:

[0024] The quantity is greater than or equal to the target quantity threshold;

[0025] The memory is greater than or equal to the second memory threshold.

[0026] In this possible implementation, two types of memory exception conditions are provided, enriching the types of memory exception conditions. For example, by obtaining Java objects whose number is greater than or equal to the target number threshold, it is possible to determine the number of Java objects with an abnormally large number in the at least one Java object. For another example, by obtaining Java objects whose memory is greater than or equal to the second memory threshold, it is possible to determine the Java objects with abnormally large memory in the at least one Java object. In this way, by setting the memory exception condition, in the Java objects that may have a memory leak, the memory exception condition is used to determine the Java objects with abnormalities, and thus the Java objects with memory leaks are determined.

[0027] In another possible implementation manner of the first aspect, the target subprocess is a fork subprocess.

[0028] In another possible implementation manner of the first aspect, after determining, in the at least one Java object, that a Java object that meets the memory exception condition is a Java object with a memory leak, the method further includes:

[0029] Correct the program code of the Java object causing the memory leak.

[0030] In this possible implementation, the program code of the Java object with the memory leak is corrected to correct the memory leak error in time, thereby ensuring the security and reliability of memory management.

[0031] In a second aspect, the present application provides an electronic device, including: a processor and a memory. The memory is used to store program codes, and the processor is used to call the program codes stored in the memory, so as to implement any one of the methods provided in the first aspect.

[0032] According to a third aspect, a computer-readable storage medium is provided, comprising a program code. When the program code is executed on an electronic device, the electronic device executes any one of the methods provided in the first aspect.

[0033] According to a fourth aspect, a computer program product is provided, including a program code. When the program code is executed on an electronic device, the electronic device executes any one of the methods provided in the first aspect.

[0034] It should be noted that the technical effects brought about by any implementation method in the second to fourth aspects can refer to the technical effects brought about by the corresponding implementation method in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 A schematic diagram of an electronic device provided in an embodiment of the present application;

[0036] Figure 2 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;

[0037] Figure 3 A schematic diagram of the software structure of an electronic device provided in an embodiment of the present application;

[0038] Figure 4 A schematic diagram of the software structure of an application management module and a memory management module provided in an embodiment of the present application;

[0039] Figure 5 A flowchart of a memory leak detection method provided in an embodiment of the present application;

[0040] Figure 6 A schematic diagram of the principle of a memory leak detection method provided in an embodiment of the present application;

[0041] Figure 7 A schematic diagram of a Java object reference relationship provided in an embodiment of the present application;

[0042] Figure 8 A schematic diagram of the framework of a memory leak detection device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0043] In the description of this application, unless otherwise specified, " / " means "or", for example, A / B can mean A or B. "And / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, "at least one" means one or more, and "plurality" means two or more. The words "first", "second", etc. do not limit the quantity and execution order, and the words "first", "second", etc. do not limit them to be different.

[0044] It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0045] The memory leak detection method provided in the embodiment of the present application can be applied in the field of memory management technology, and specifically can be applied in the memory leak scenario of Java heap.

[0046] Among them, Java heap usually refers to the dynamic memory defined in the virtual machine (Virtual Machine), which is a memory area. A virtual machine refers to a complete computer system obtained by an electronic device through software simulation. For example, in an embodiment of the present application, a virtual machine can be a computer system obtained by a terminal through software simulation, or it can be a computer system obtained by a server through software simulation. The embodiment of the present application does not limit the application device of memory leak detection.

[0047] Memory leak refers to the situation where the application fails to release memory that is no longer in use due to negligence or error. For example, after the application allocates a certain segment of memory, due to design errors or other reasons, there is no corresponding release logic for this segment of memory, so the control of this segment of memory is lost before it is released, resulting in memory waste. Furthermore, when the application runs for a long time, the memory will be continuously consumed, eventually leading to low memory and even crashes. Therefore, the detection of memory leaks is very important.

[0048] Usually, the memory of the Java heap (the size of the memory occupied) will be set with a memory upper limit. Taking the Android system as an example, the memory upper limit can be set to 512MB. In some possible implementations, when the memory of the Java heap is greater than 512MB, it is easy to trigger a memory overflow (out of memory) of the virtual machine. Among them, memory overflow refers to when the memory requested by the application exceeds the memory of the Java heap, making it very likely that the application will be unable to allocate memory, resulting in insufficient memory and then causing problems such as application crashes.

[0049] When a Java heap memory overflow occurs, the error stack is usually printed to determine the stack information of the exception. However, the stack information currently determined is often the stack information of the failed memory application, which has no direct correlation with the memory leak, making it difficult to locate the memory leak problem.

[0050] In view of this, the embodiment of the present application provides a memory leak detection method. When the memory of the Java heap is greater than the first memory threshold, the target subprocess in the application process is used to execute the process of obtaining the Java object reference relationship of the Java heap. In this way, the operation of obtaining the Java object reference relationship is completed in the target subprocess of the application process. On the one hand, the target subprocess will inherit the data resources of the parent process (i.e., the application process), thereby effectively reducing the performance overhead. On the other hand, the target subprocess can be effectively isolated from other threads in the application process, thereby avoiding the target subprocess from affecting other threads in the application process, thereby ensuring the stability of memory leak detection. Moreover, based on the Java object reference relationship, at least one Java object in the running state of the memory is determined, and the Java object that may have a memory leak is determined. Furthermore, by setting a memory exception condition, in the Java object that may have a memory leak, the memory exception condition is used to determine the abnormal Java object, thereby determining the Java object with a memory leak. In this way, a memory leak detection scheme is provided, which can ensure the stability and security of memory management.

[0051] In a possible implementation, the memory leak detection method provided in the embodiment of the present application can be applied to Figure 1 The electronic device 100 shown is exemplary. Figure 1 A schematic diagram of an electronic device provided in an embodiment of the present application.

[0052] In the embodiment of the present application, the electronic device 100 may be a terminal 101 or a server 102 .

[0053] Exemplarily, the terminal 101 may be at least one of a smart phone, a smart watch, a desktop computer, a laptop computer, a virtual reality terminal, an augmented reality terminal, a wireless terminal, and a laptop computer.

[0054] As another example, server 102 can be an independent physical server, such as a general-purpose server, a graphics processing unit (GPU) server, a data processing unit (DPU) server, an artificial intelligence (AI) server, etc., or it can be at least one of the cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks, and big data or artificial intelligence platforms. The embodiments of the present application are not limited to this.

[0055] In some embodiments, different types of applications may be run on the electronic device 100. Generally, when an application in the electronic device 100 is running, a memory application needs to be made to ensure the normal operation of the application.

[0056] The electronic device 100 is provided with a memory leak detection function. In the embodiment of the present application, the electronic device 100 is used to, in response to the memory of the Java heap being greater than the first memory threshold, obtain the Java object reference relationship of the Java heap based on the target subprocess in the application process; based on the Java object reference relationship, determine at least one Java object in the Java heap whose memory is in a running state; and among the at least one Java object, determine that the Java object that meets the memory exception condition is a Java object with a memory leak.

[0057] For example, taking the terminal as an example, Figure 1 The structural diagram of the electronic device 100 in FIG. Figure 2 shown. Figure 2 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.

[0058] See also Figure 2 The electronic device 100 may include a processor 210, an external memory interface 220, an internal memory 221, a universal serial bus (USB) interface 230, a charging management module 240, an antenna 1, an antenna 2, a mobile communication module 250, a wireless communication module 260, an audio module 270, a sensor module 280, a button 290, etc. The sensor module 280 may include a pressure sensor 280A, a touch sensor 280B, etc.

[0059] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0060] The processor 210 may include one or more processing units, for example, the processor 210 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0061] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0062] The processor 210 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. The memory may store instructions or data that the processor 210 has just used or cyclically used. If the processor 210 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 210, and thus improves the efficiency of the system.

[0063] In some embodiments, the processor 210 may include one or more interfaces. The interface 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 USB interface 230, etc.

[0064] The USB interface 230 is an interface that complies with the USB standard specification, and can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 230 can be used to connect a charger to charge the electronic device 100, and can also be used to transfer data between the electronic device 100 and a peripheral device. It can also be used to connect headphones to play audio through the headphones. The interface can also be used to connect other electronic devices, such as AR devices, etc.

[0065] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0066] The charging management module 240 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.

[0067] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 250, the wireless communication module 260, the modem processor, the baseband processor, and the like.

[0068] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0069] The mobile communication module 250 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 250 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 250 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 250 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 250 can be set in the processor 210. In some embodiments, at least some of the functional modules of the mobile communication module 250 can be set in the same device as at least some of the modules of the processor 210.

[0070] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker, a receiver, etc.), or displays an image or video through a display screen. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 210 and be set in the same device as the mobile communication module 250 or other functional modules.

[0071] The wireless communication module 260 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (bluetoo2, BT), global navigation satellite system (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field communication technology (near field communication, NFC), infrared technology (infrared, IR), etc. applied to the electronic device 100. The wireless communication module 260 can be one or more devices integrating at least one communication processing module. The wireless communication module 260 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and filters it, and sends the processed signal to the processor 210. The wireless communication module 260 can also receive the signal to be sent from the processor 210, modulate the frequency, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0072] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 250, and antenna 2 is coupled to wireless communication module 260, so that electronic device 100 can communicate with the network and other devices through wireless communication technology.

[0073] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of electronic device 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0074] The external memory interface 220 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 210 through the external memory interface 220 to implement a data storage function, such as storing files such as music and videos in the external memory card.

[0075] The internal memory 221 can be used to store computer executable program codes, which include instructions. The processor 210 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 221. The internal memory 221 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 221 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0076] The audio module 270 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signal. The audio module 270 can also be used to encode and decode audio signals. In some embodiments, the audio module 270 can be arranged in the processor 210, or some functional modules of the audio module 270 can be arranged in the processor 210.

[0077] The pressure sensor 280A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. There are many types of pressure sensors 280A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. A capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 280A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure based on the change in capacitance. The electronic device 100 can also calculate the touch position based on the detection signal of the pressure sensor 280A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.

[0078] The touch sensor 280B, also called a "touch panel", is used to detect a touch operation applied thereto or thereabout. The touch sensor may transmit the detected touch operation to an application processor to determine the type of touch event.

[0079] The buttons 290 include a power button, a volume button, etc. The buttons 290 may be mechanical buttons or touch buttons.

[0080] It should be pointed out that Figure 2 The structure shown in the figure does not constitute a limitation on the electronic device, except Figure 2 In addition to the components shown, the electronic device may include more or fewer components than shown, or combine certain components, or arrange the components differently.

[0081] The software system of the electronic device can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to illustrate the software structure of the electronic device. Figure 3 A schematic diagram of the software structure of an electronic device provided in an embodiment of the present application.

[0082] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system can be divided into four layers, from top to bottom: application layer, application framework layer, system library and kernel layer.

[0083] The application layer can include a series of application packages.

[0084] like Figure 3 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.

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

[0086] like Figure 3 As shown, the application framework layer may include an application management module, a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

[0087] The application management module is used to provide a function of querying the log file of the Java heap. For example, in an embodiment of the present application, the application management module is used to obtain the Java object reference relationship of the Java heap based on the target subprocess in the application process. For example, in some embodiments, the application management module is used to obtain the Java object reference relationship of the Java heap from the log file of the Java heap based on the target subprocess in the application process.

[0088] The window manager is used to manage window programs. For example, in some possible implementations, the window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc.

[0089] The content provider is used to store and obtain data and make the data accessible to the application. Exemplarily, the data may include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

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

[0091] The phone manager is used to provide communication functions of the electronic device 100. For example, the management of call status (including answering, hanging up, etc.).

[0092] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0093] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is prompted in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.

[0094] When executing programs, the Android system uses the Android runtime that comes with the system library. The Android runtime is responsible for the scheduling and management of the Android system.

[0095] In some possible implementations, the Android runtime mainly includes a core library and a virtual machine.

[0096] In the core library, one part is the function that needs to be called by the Java language, and the other part is the core library of the Android system.

[0097] The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection. In some possible implementations, the application layer and the application framework layer run in the virtual machine. For example, the virtual machine can execute Java files of the application layer and the application framework layer as binary files.

[0098] In addition to the above-mentioned Android runtime, the system library may also include a memory management module and a memory leak detection module.

[0099] The memory management module is used to provide a memory monitoring function for the Java heap. For example, in an embodiment of the present application, the memory management module is used to monitor whether the memory of the Java heap is greater than a first memory threshold, and when the memory of the Java heap is greater than the first memory threshold, trigger the execution of a subsequent process based on a target subprocess in the application process to obtain a Java object reference relationship of the Java heap.

[0100] The memory leak detection module is used to provide a detection function for memory leaks. For example, in an embodiment of the present application, the memory leak detection module is used to determine at least one Java object in the Java heap whose memory is in a running state based on the Java object reference relationship, and in the at least one Java object, determine that the Java object that meets the memory exception condition is a Java object with a memory leak.

[0101] In addition, the system library may also include multiple functional modules, such as a surface manager, a media library, a 3D graphics processing library (such as OpenGL ES), a 2D graphics engine (such as SGL), etc.

[0102] The surface manager is used to manage the display subsystem and provide the fusion of two-dimensional and three-dimensional layers for multiple applications.

[0103] The media library supports playback and recording of multiple common audio and video formats, as well as static image files, etc. In some possible implementations, the media library can support multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0104] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing.

[0105] A 2D graphics engine is a drawing engine for 2D drawings.

[0106] The kernel layer is an abstract layer between hardware and software. For example, in some possible implementations, the kernel layer includes at least a display driver, a camera driver, an audio driver, and a sensor driver.

[0107] Based on the above Figure 3 The software structure shown in FIG. 1 and the implementation process of the memory leak detection method provided in the embodiment of the present application can be combined to divide some structures in the above software structure. For example, Figure 4 A schematic diagram of the software structure of an application management module and a memory management module provided in an embodiment of the present application.

[0108] See also Figure 4 , the application management module (App) can include Figure 4 The application process shown. In an embodiment of the present application, the application process is used to provide a function of querying the log file of the Java heap to obtain the Java object reference relationship of the Java heap. In an embodiment of the present application, the application process is used to obtain the Java object reference relationship of the Java heap based on the target subprocess in the application process. For example, in some embodiments, the application process is used to obtain the Java object reference relationship of the Java heap from the log file of the Java heap based on the target subprocess in the application process.

[0109] In some possible implementations, the application process may include a private signal monitoring thread, a public signal monitoring thread, and a log monitoring thread.

[0110] Among them, the private signal listening thread provides the function of managing public signals. In an embodiment of the present application, the private signal listening thread is used to reset the signal processing function of the public signal to a preset signal processing function based on the signal processing function of the private signal after listening to the private signal, and the preset signal processing function is used to trigger the target subprocess in the log listening thread.

[0111] The public signal listening thread provides a function of triggering a log dump. In an embodiment of the present application, after the public signal is listened to, the public signal listening thread triggers the target subprocess in the log listening thread based on the signal processing function of the public signal to instruct the target subprocess in the log listening thread to obtain the Java object reference relationship of the Java heap and store it.

[0112] The log listening thread provides a function of obtaining the Java object reference relationship of the Java heap. In an embodiment of the present application, the log listening thread is used to obtain the Java object reference relationship of the Java heap from the log file of the Java heap through the target subprocess in the log listening thread. Among them, the target subprocess can be a fork subprocess. In some possible implementations, the process of obtaining the Java object reference relationship of the Java heap can be: traversing the Java objects in the log file of the Java heap, obtaining the reference relationship of multiple dynamic Java objects in the Java heap, that is, obtaining the Java object reference relationship.

[0113] See also Figure 4 , the memory management module (Native) can include Figure 4 In the embodiment of the present application, the daemon process is used to monitor the memory of the Java heap in real time, and when it is detected that the memory of the Java heap is greater than the first memory threshold, the application process is triggered to execute the process of obtaining the Java object reference relationship of the Java heap.

[0114] In some possible implementations, the daemon process may include a signal management thread, a session control thread, and a log storage thread.

[0115] The signal management thread is used to send a private signal to the application process to trigger the private signal monitoring thread in the application process to execute the process of resetting the public signal.

[0116] The session control thread is used to send a public signal to the application process to trigger the public signal listening thread in the application process to execute the process of triggering the log listening thread to obtain the Java object reference relationship.

[0117] The log storage thread is used to store the log files of the Java heap. In the embodiment of the present application, the log monitoring thread can obtain the log files of the Java heap from the log storage thread, and then obtain the Java object reference relationship of the Java heap from the log files of the Java heap.

[0118] Figure 5 A flowchart of a memory leak detection method provided in an embodiment of the present application. Figure 5 The method includes the following S501-S503:

[0119] S501: In response to a Java heap memory being greater than a first memory threshold, obtaining a Java object reference relationship of the Java heap based on a target subprocess in an application process.

[0120] Among them, the first memory threshold is used to represent the memory upper limit of the Java heap. It should be noted that the memory size of the Java heap is usually set with a memory upper limit. Taking the Android system as an example, the memory upper limit can be set to 512MB. Exemplarily, the first memory threshold can be set to 500MB, 512MB or other values. The embodiment of the present application does not limit the setting of the first memory threshold. In the embodiment of the present application, the target child process is the fork child process.

[0121] Java object reference relationships are used to represent reference relationships between Java objects, such as one-to-one, one-to-many, many-to-many, or many-to-one relationships, etc. Java objects are programming concepts used to represent things or concepts, and can be encapsulated units consisting of data (attributes) and methods (behaviors).

[0122] S502: Based on the Java object reference relationship, determine at least one Java object in the Java heap memory that is in a running state.

[0123] Among them, at least one Java object in a running state indicates that the at least one Java object is still in use, which also indicates that the at least one Java object is a Java object that has not been actively released, that is, these Java objects in a running state are Java objects that may have memory leaks.

[0124] S503: Determine, in the at least one Java object, a Java object that meets the memory exception condition as a Java object with a memory leak.

[0125] In some possible implementations, the memory exception condition includes at least one of the following conditions: the quantity is greater than or equal to a target quantity threshold; the memory is greater than or equal to a second memory threshold.

[0126] Among them, the target quantity threshold is a pre-set quantity threshold, such as 10, 15 or other numerical values. It should be understood that the target quantity threshold is used to filter out the abnormally large number of Java objects in the at least one Java object. The embodiment of the present application does not limit the setting of the target quantity threshold. The second memory threshold is a pre-set memory threshold, such as 200MB, 250MB or other thresholds. It should be understood that the second memory threshold is used to filter out the Java objects with abnormally large memory in the at least one Java object. The embodiment of the present application does not limit the setting of the second memory threshold.

[0127] The technical solution provided by the embodiment of the present application, when the memory of the Java heap is greater than the first memory threshold, uses the target child process in the application process to execute the process of obtaining the Java object reference relationship of the Java heap. In this way, the operation of obtaining the Java object reference relationship is completed in the target child process of the application process. On the one hand, the target child process will inherit the data resources of the parent process (i.e., the application process), thereby effectively reducing the performance overhead. On the other hand, the target child process can be effectively isolated from other threads in the application process, thereby avoiding the target child process from affecting other threads in the application process, thereby ensuring the stability of memory leak detection. Moreover, based on the Java object reference relationship, at least one Java object in the running state of the memory is determined, and the Java object that may have a memory leak is determined. Furthermore, by setting a memory exception condition, in the Java object that may have a memory leak, the memory exception condition is used to determine the abnormal Java object, thereby determining the Java object with a memory leak. In this way, a memory leak detection scheme is provided, which can ensure the stability and security of memory management.

[0128] Figure 6 A flowchart of a memory leak detection method provided in an embodiment of the present application. Figure 6 The method may be executed by an electronic device, for example, by a processor of the electronic device, and includes the following S601-S605:

[0129] S601: In response to the memory of the Java heap being greater than a first memory threshold, the electronic device resets the signal processing function of the public signal to a preset signal processing function based on the signal processing function of the private signal.

[0130] Among them, the first memory threshold is used to represent the memory upper limit of the Java heap. It should be noted that the memory size of the Java heap is usually set with a memory upper limit. Taking the Android system as an example, the memory upper limit can be set to 512MB. Exemplarily, the first memory threshold can be set to 500MB, 512MB or other values. The embodiment of the present application does not limit the setting of the first memory threshold.

[0131] Private signals are used for synchronization between different processes or threads in different processes. In an embodiment of the present application, the signal processing function of the private signal is used to reset the signal processing function of the public signal to a preset signal processing function. The preset signal processing function is used to trigger the target child process in the log monitoring thread to obtain the Java object reference relationship of the Java heap.

[0132] Public signals are used for mutual exclusion between different processes or threads in different processes. In the embodiment of the present application, the signal processing function of the public signal is used to trigger the target child process in the log monitoring thread to obtain the Java object reference relationship of the Java heap.

[0133] In some possible implementations, a daemon process built into the electronic device is capable of monitoring the memory of the Java heap in real time. When it is detected that the memory of the Java heap is greater than a first memory threshold, a private signal is sent to an application process built into the electronic device to instruct the application process to reset the signal processing function of the public signal to a preset signal processing function based on the signal processing function of the private signal.

[0134] Further, taking the signal management thread built into the daemon process and the private signal monitoring thread built into the application process as an example, the above process may be: when the daemon process detects that the memory of the Java heap is greater than the first memory threshold, the signal management thread built into the daemon process sends a private signal to the application process. After the private signal is monitored, the private signal monitoring thread built into the application process resets the signal processing function of the public signal to the preset signal processing function based on the signal processing function of the private signal.

[0135] In the above embodiment, when it is detected that the memory of the Java heap is greater than the first memory threshold, the signal processing function of the public signal is first reset to a preset signal processing function based on the signal processing function of the private signal to ensure that the signal processing function of the public signal is the preset signal processing function, thereby avoiding the problem of memory leak detection failure due to an incorrect signal processing function, and effectively improving the stability of memory leak detection.

[0136] S602: The electronic device triggers a target subprocess in the log monitoring thread based on the signal processing function of the public signal, and obtains a Java object reference relationship of the Java heap from the log file of the Java heap.

[0137] The Java object reference relationship is used to represent the reference relationship between Java objects in the Java heap, such as one-to-one, one-to-many, many-to-many or many-to-one relationships, etc. A Java object is a programming concept used to represent things or concepts, and can be an encapsulation unit composed of data (attributes) and methods (behaviors).

[0138] In some possible implementations, the Java object reference relationship can be represented by a tree diagram. For example, Figure 7 A schematic diagram of a Java object reference relationship provided in an embodiment of the present application. Figure 7 ,exist Figure 7The tree diagram shown shows multiple Java objects extending from the root node, such as object A, object B, object C, object D, object E, and object F.

[0139] In some possible implementations, after resetting the signal processing function of the public signal to a preset signal processing function, the daemon process built into the electronic device may send a public signal to the application process built into the electronic device. The application process responds to the public signal and triggers a target child process in the log monitoring thread based on the signal processing function of the public signal to obtain a Java object reference relationship of the Java heap from the log file of the Java heap.

[0140] Further, taking the built-in session control thread of the daemon process and the built-in public signal monitoring thread of the application process as an example, the above process may be: sending a public signal to the application process through the built-in session control thread of the daemon process. After monitoring the public signal, the built-in public signal monitoring thread of the application process triggers the target child process in the log monitoring thread based on the signal processing function of the public signal, and obtains the Java object reference relationship of the Java heap from the log file of the Java heap.

[0141] In the embodiment of the present application, private signals and public signals are newly introduced. On the one hand, the signal processing function of the private signal is used to ensure that the signal processing function of the public signal is a preset signal processing function, so as to avoid the problem of memory leak detection failure caused by an error in the signal processing function, and effectively improve the stability of memory leak detection. On the other hand, the signal processing function of the public signal is used to obtain the Java object reference relationship of the Java heap, which can ensure that the process of obtaining the Java object reference relationship of the Java heap is executed only based on one or a group of processes (or threads), which can effectively avoid the current process (or thread) from affecting other processes (or threads), thereby ensuring the stability and security of memory leak detection.

[0142] In the embodiment of the present application, the target child process is a fork child process. For example, in some possible implementations, the fork() function can be used to create a fork child process, so that the created child process is a replica of the parent process, and can copy the context, code area, data area, memory information, signal processing function and other resources of the parent process. The log file of the Java heap is used to record the stack information of the Java heap, such as the Java object reference relationship.

[0143] In some possible implementations, the Java object reference relationship may include reference relationships of multiple dynamic Java objects. Accordingly, the process of obtaining the Java object reference relationship of the Java heap from the log file of the Java heap through the target subprocess in the log monitoring thread may be: obtaining the reference relationship of multiple dynamic Java objects in the Java heap from the log file of the Java heap through the target subprocess in the log monitoring thread to obtain the Java object reference relationship. Among them, the dynamic Java object refers to the dynamic memory object in the Java heap, and its memory is usually changeable. It should be noted that since memory leaks are usually for dynamic memory leaks based on the Java heap, obtaining the reference relationship of multiple dynamic Java objects is helpful for subsequent memory leak detection.

[0144] The above S602 corresponds to Figure 5 In S501, based on the target child process in the application process, the process of obtaining the Java object reference relationship of the Java heap is performed. In the above embodiment, the target child process in the log monitoring thread can be triggered to execute the subsequent process of obtaining the Java object reference relationship of the Java heap through the signal processing function of the public signal. In this way, a lightweight solution for obtaining the Java object reference relationship is provided, which can effectively reduce performance overhead.

[0145] In the related art, the Java object reference relationship of the Java heap is usually read directly inside the application process, which is equivalent to using the entire application process to read the Java object reference relationship, so that all threads in the application process will be suspended, resulting in a large performance overhead. Compared with the related art, the embodiment of the present application can obtain the Java object reference relationship of the Java heap with the smallest possible performance overhead, thereby ensuring the security and reliability of memory leak detection.

[0146] S603: The electronic device determines, based on the Java object reference relationship, at least one Java object in the Java heap memory that is in a running state.

[0147] In some possible implementations, the Java object reference relationship is represented by a tree diagram, and the process of determining at least one Java object in the Java heap memory that is in a running state may be: in the Java object reference relationship, at least one Java object reached by taking the Java object corresponding to the root node as the starting point is determined as the at least one Java object in the Java heap memory that is in a running state.

[0148] The Java object corresponding to the root node may be GC roots. The GC roots are a collection of active Java objects, such as a collection of objects directly referenced by variables such as constants, static variables, and global variables. It should be understood that GC roots will never be released.

[0149] It should be understood that the at least one Java object reached from the Java object corresponding to the root node as the starting point refers to a Java object that is connected to the Java object corresponding to the root node through a path. Figure 7 ,exist Figure 7 In the tree diagram shown, objects A, B, C, D, E, and F are all connected to the Java object corresponding to the root node by a path. Figure 7 The objects A, B, C, D, E, and F shown are all Java objects in running state.

[0150] In the above embodiment, a method for determining a Java object in a running state based on a Java object reference relationship is provided, so that the Java object in a running state can be determined quickly and efficiently, thereby improving the efficiency of determining the Java object in a running state.

[0151] S604: The electronic device determines, among the at least one Java object, that a Java object that meets a memory exception condition is a Java object with a memory leak.

[0152] In some possible implementations, the memory exception condition includes at least one of the following conditions: the quantity is greater than or equal to a target quantity threshold; the memory is greater than or equal to a second memory threshold.

[0153] Among them, the target quantity threshold is a pre-set quantity threshold, such as 10, 15 or other numerical values. It should be understood that the target quantity threshold is used to filter out the abnormally large number of Java objects in the at least one Java object. The embodiment of the present application does not limit the setting of the target quantity threshold. The second memory threshold is a pre-set memory threshold, such as 200MB, 250MB or other thresholds. It should be understood that the second memory threshold is used to filter out the Java objects with abnormally large memory in the at least one Java object. The embodiment of the present application does not limit the setting of the second memory threshold.

[0154] For example, in some possible implementations, the process of determining that the Java objects that meet the memory exception condition are Java objects with memory leaks in the at least one Java object may be: determining that the Java objects whose number is greater than or equal to the target number threshold are Java objects with memory leaks in the at least one Java object. It should be noted that the number of Java objects included in the Java object reference relationship may be one or more. In this way, by obtaining the Java objects whose number is greater than or equal to the target number threshold, it is possible to determine that the number of Java objects in the at least one Java object is abnormally large.

[0155] For example, see Figure 7 , assuming the target number threshold is 2, in Figure 7 Among the at least one Java object shown, the Java objects whose number is greater than or equal to the target number threshold may be object B and object C, which indicates that object B and object C are Java objects with memory leaks.

[0156] Alternatively, for example, in some other possible implementations, in the at least one Java object, the process of determining that the Java object whose memory is greater than or equal to the second memory threshold is a Java object with a memory leak may also be: in the at least one Java object, determining that the Java object whose memory is greater than or equal to the second memory threshold is a Java object with a memory leak. It should be noted that the Java object reference relationship may include the memory of each Java object. In this way, by obtaining the Java object whose memory is greater than or equal to the second memory threshold, the Java object with abnormally large memory in the at least one Java object can be determined.

[0157] It is worth noting that the above number being greater than or equal to the target number threshold and the memory being greater than or equal to the second memory threshold are merely exemplary descriptions of memory abnormality conditions. In other possible implementations, the memory abnormality condition can also be set to other types of conditions. The present application embodiment does not limit the setting of the memory abnormality condition.

[0158] In the above embodiment, two types of memory exception conditions are provided, which enrich the types of memory exception conditions. For example, by obtaining Java objects whose number is greater than or equal to the target number threshold, it is possible to determine the number of abnormally large Java objects in the at least one Java object. For another example, by obtaining Java objects whose memory is greater than or equal to the second memory threshold, it is possible to determine the Java objects with abnormally large memory in the at least one Java object. In this way, by setting the memory exception condition, in the Java objects that may have memory leaks, the memory exception condition is used to determine the abnormal Java objects, and thus the Java objects with memory leaks are determined.

[0159] S605: The electronic device corrects the program code of the Java object with the memory leak.

[0160] In some possible implementations, the electronic device may analyze the program code of the Java object with the memory leak, and then automatically correct the program code of the Java object with the memory leak according to the analysis result of the memory leak.

[0161] Alternatively, in some possible implementations, the electronic device may also output the program code of the Java object of the memory leak. For example, the program code of the Java object of the memory leak is output to a display screen connected to the electronic device for a technician to view and then manually correct. Further, after obtaining the analysis result of the memory leak, the electronic device may also output the analysis result of the memory leak to a display screen connected to the electronic device for a technician to refer to.

[0162] In this way, by correcting the program code of the Java object with the memory leak, the memory leak error can be corrected in time, thereby ensuring the security and reliability of memory management.

[0163] The technical solution provided by the embodiment of the present application, when the memory of the Java heap is greater than the first memory threshold, uses the target child process in the application process to execute the process of obtaining the Java object reference relationship of the Java heap. In this way, the operation of obtaining the Java object reference relationship is completed in the target child process of the application process. On the one hand, the target child process will inherit the data resources of the parent process (i.e., the application process), thereby effectively reducing the performance overhead. On the other hand, the target child process can be effectively isolated from other threads in the application process, thereby avoiding the target child process from affecting other threads in the application process, thereby ensuring the stability of memory leak detection. Moreover, based on the Java object reference relationship, at least one Java object in the running state of the memory is determined, and the Java object that may have a memory leak is determined. Furthermore, by setting a memory exception condition, in the Java object that may have a memory leak, the memory exception condition is used to determine the abnormal Java object, thereby determining the Java object with a memory leak. In this way, a memory leak detection scheme is provided, which can ensure the stability and security of memory management.

[0164] Figure 8 A schematic diagram of a memory leak detection device provided in an embodiment of the present application. Figure 8 The memory leak detection device includes an acquisition module 801 and a determination module 802.

[0165] The acquisition module 801 is used for acquiring a Java object reference relationship of the Java heap based on a target subprocess in an application process in response to the memory of the Java heap being greater than a first memory threshold;

[0166] A determination module 802 is used to determine at least one Java object in the Java heap memory that is in a running state based on the Java object reference relationship;

[0167] The determination module 802 is further configured to determine, among the at least one Java object, a Java object that meets the memory exception condition as a Java object with a memory leak.

[0168] The technical solution provided by the embodiment of the present application, when the memory of the Java heap is greater than the first memory threshold, uses the target child process in the application process to execute the process of obtaining the Java object reference relationship of the Java heap. In this way, the operation of obtaining the Java object reference relationship is completed in the target child process of the application process. On the one hand, the target child process will inherit the data resources of the parent process (i.e., the application process), thereby effectively reducing the performance overhead. On the other hand, the target child process can be effectively isolated from other threads in the application process, thereby avoiding the target child process from affecting other threads in the application process, thereby ensuring the stability of memory leak detection. Moreover, based on the Java object reference relationship, at least one Java object in the running state of the memory is determined, and the Java object that may have a memory leak is determined. Furthermore, by setting a memory exception condition, in the Java object that may have a memory leak, the memory exception condition is used to determine the abnormal Java object, thereby determining the Java object with a memory leak. In this way, a memory leak detection scheme is provided, which can ensure the stability and security of memory management.

[0169] In some possible implementations, the application process includes a log monitoring thread, and the log monitoring thread includes the target subprocess; the acquisition module 801 is specifically used to:

[0170] Based on the signal processing function of the public signal, the target subprocess in the log monitoring thread is triggered, and the Java object reference relationship of the Java heap is obtained from the log file of the Java heap.

[0171] In some possible implementations, the target child process is a fork child process.

[0172] In some possible implementations, the device further includes a resetting module, configured to:

[0173] Based on the signal processing function of the private signal, the signal processing function of the public signal is reset to a preset signal processing function, and the preset signal processing function is used to trigger the target subprocess in the log monitoring thread.

[0174] In some possible implementations, the Java object reference relationship includes: a reference relationship of multiple dynamic Java objects.

[0175] In some possible implementations, the Java object reference relationship is represented by a tree diagram;

[0176] The determination module 802 is specifically used for:

[0177] In the Java object reference relationship, at least one Java object reached by taking the Java object corresponding to the root node as a starting point is determined as at least one Java object in the Java heap memory in a running state.

[0178] In some possible implementations, the memory exception condition includes at least one of the following conditions:

[0179] The quantity is greater than or equal to the target quantity threshold;

[0180] The memory is greater than or equal to the second memory threshold.

[0181] In some possible implementations, the device further includes a correction module, configured to:

[0182] Correct the program code of the Java object causing the memory leak.

[0183] It is understandable that the electronic device (such as a terminal or a server) in the embodiment of the present application includes a hardware structure and / or software module corresponding to each function in order to realize the above functions. Those skilled in the art should be easily aware that, in conjunction with the units and algorithm steps of each example described in the embodiments disclosed herein, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but this implementation should not be considered to exceed the scope of the embodiments of the present application.

[0184] The embodiment of the present application also provides an electronic device, including: a processor and a memory. The processor is connected to the memory, the memory is used to store program codes, and the processor executes the program codes stored in the memory, thereby implementing the memory leak detection method provided in the embodiment of the present application.

[0185] An embodiment of the present application further provides a computer-readable storage medium having program code stored thereon. When the program code is executed on an electronic device, the electronic device executes each function or step executed by the electronic device in the above method embodiment.

[0186] An embodiment of the present application also provides a computer program product, including program code. When the program code is executed on an electronic device, the electronic device executes each function or step executed by the electronic device in the above method embodiment.

[0187] Among them, the electronic device, computer-readable storage medium or computer program product provided in the embodiments of the present application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0188] Through the description of the above implementation methods, technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device (such as an electronic device) is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device (such as an electronic device) and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0189] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices (such as electronic devices) and methods can be implemented in other ways. For example, the device (such as electronic device) embodiments described above are only schematic. For example, the division of the module or unit is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0190] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0191] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0192] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of the method of each embodiment of the present application. The aforementioned storage medium includes: flash memory, mobile hard disk, read-only memory, random access memory, disk or optical disk and other media that can store program codes.

[0193] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A memory leak detection method, characterized in that: include: In response to the memory of the Java heap being greater than the first memory threshold, based on the signal processing function of the private signal, resetting the signal processing function of the public signal to a preset signal processing function, wherein the preset signal processing function is used to trigger a target subprocess in a log monitoring thread of the application process; Based on the signal processing function of the public signal, trigger the target subprocess, and obtain the Java object reference relationship of the Java heap from the log file of the Java heap; the Java object reference relationship is represented by a tree diagram; In the Java object reference relationship, determining at least one Java object reached by taking the Java object corresponding to the root node as a starting point as at least one Java object in a running state in the memory of the Java heap; Among the at least one Java object, a Java object that meets the memory exception condition is determined to be a Java object with memory leak.

2. The method according to claim 1, characterized in that The Java object reference relationship includes: a reference relationship of multiple dynamic Java objects.

3. The method according to claim 1, characterized in that The memory abnormality condition includes at least one of the following conditions: The quantity is greater than or equal to the target quantity threshold; The memory is greater than or equal to the second memory threshold.

4. The method according to claim 1, characterized in that: The target subprocess is the fork subprocess.

5. The method according to claim 1, characterized in that After determining that a Java object that satisfies the memory exception condition in the at least one Java object is a Java object with a memory leak, the method further includes: The program code of the Java object with the memory leak is corrected.

6. An electronic device, characterized in that: It comprises a memory and a processor; the memory is used to store program code; the processor is used to call the program code to execute the method according to any one of claims 1 to 5.

7. A computer-readable storage medium, characterized in that: The method comprises a program code, and when the program code is executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

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

    CN111694673A

  • Memory leak processing method and device, computer equipment and storage medium

    CN116204449A