Method and device for detecting memory leak, equipment and storage medium

By counting the memory usage count information of the target memory of the target memory, determining whether the memory leak condition is met, solving the problem of detecting memory leaks in the prior art occupies a large amount of processor resources, and achieving simplified statistical computing and resource savings.

CN119718731APending Publication Date: 2025-03-28CHENGDU HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311281261.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-28
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

The prior art requires a large amount of processor resources to detect memory leaks and is statistically complex.

Method used

By counting the memory usage count information of the target process on the target memory, including the number of memory allocations and releases, we can judge whether the memory leak conditions are met, and output the memory leak caused by the target process.

Benefits of technology

It realizes the determination of whether the target process causes memory leakage through simple memory usage statistics, saves a lot of processor resources, and simplifies statistical calculations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718731A_ABST
    Figure CN119718731A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a method and device for detecting memory leak, equipment and a storage medium, and belongs to the technical field of memory management. In the method, on the basis of an allocation event and a release event of a target memory initiated by a target process, memory use counting information of the target process on the target memory is counted, and a memory leak detection result is obtained by judging whether the memory use counting information meets a memory leak condition or not. By adopting the method, whether the target process causes the memory leakage of the target memory or not can be judged through simple statistics of the number of times of memory use, statistics of the total amount of memory application and the total amount of memory release is not needed, relatively complicated statistical calculation is replaced by relatively simple statistical calculation, and a large amount of processor resources are saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of memory management, and in particular to a method, apparatus, device and storage medium for detecting memory leaks. Background Art

[0002] With the development of computer technology, there are more and more processors, such as central processing unit (CPU), neural network processor (NPU), graphics processing unit (GPU), etc. Different processors manage their own memory resources. For example, CPU manages system memory, GPU manages display memory, etc. It is more important to effectively allocate and release memory and prevent memory leaks. Memory leak means that the allocated memory is not released normally. For example, the image recognition application does not release the memory after applying for memory for image recognition.

[0003] In the related art, the total amount of memory applications and the total amount of memory releases can be counted, and based on the above statistics, it can be determined whether a system memory leak occurs.

[0004] The above method requires a large amount of processor resources. Summary of the invention

[0005] The present disclosure provides a method, apparatus, device and storage medium for detecting memory leaks, which can detect whether a process causes memory leaks. The technical solution is as follows:

[0006] In a first aspect, a method for detecting memory leaks is provided, the method comprising: based on allocation events and release events of a target memory initiated by a target process, counting memory usage count information of the target memory by the target process, wherein the target memory is memory managed by a target processor; when a target trigger event occurs, if the memory usage count information meets a memory leak condition, outputting that the target process causes a memory leak in the target memory.

[0007] The main interface of the detection application can be provided with a memory selection bar, an application selection bar, a start detection control, and an end detection control. The technician can click on the memory selection bar to select the target memory, select the target application in the application selection bar, and then click on the start detection control. At this time, the detection application starts to monitor the instructions sent by the target application to the system program, and counts the memory usage count information of the target process for the target memory. When a target trigger event is detected, it determines whether the memory usage count information meets the memory leak condition.

[0008] Technicians can perform any operation in the target application, or the operation of the target application can also be automatically controlled by a preset script. The above-mentioned manual operations or automatic operations performed by the script can include operations corresponding to all functions in the target application, or can only include some functions in the target application. These functions may involve memory allocation and release, and functions that do not involve memory allocation and release may not be tested.

[0009] In this way, through simple memory usage statistics, it is possible to determine whether the target process causes a memory leak in the target memory. There is no need to count the total amount of memory requested and released. Simpler statistical calculations replace more complex statistical calculations, saving a lot of processor resources.

[0010] In a possible implementation manner, the target triggering event includes receiving a memory leak detection instruction.

[0011] In addition, the target trigger event may also be the detection that the target process is idle for a time period exceeding a time threshold, such as half an hour, one hour, etc. The target trigger event may also be the reaching of a specified time point, which may be preset by a technician and may be set to any time point in the idle period, such as 2 a.m., etc.

[0012] In this way, memory leak detection can be triggered in a variety of ways, and the target process that causes the target memory to leak can be discovered in a timely manner.

[0013] In one possible implementation, the target processor is a central processing unit, a neural network processor, or a graphics processor.

[0014] In this way, memory leaks caused by applications in memory managed by different computing hardware can be detected.

[0015] In a possible implementation, the memory usage count information includes the number of memory allocations and the number of memory releases.

[0016] In this way, the number of memory allocations and memory releases can be clearly recorded, and it can be clearly discovered whether the target process causes a memory leak in the target memory and the number of memory leaks, making it easier for technicians to modify the code.

[0017] In a possible implementation, the memory leak condition includes that the number of memory allocations is greater than the number of memory releases.

[0018] In this way, it is possible to determine whether the target process causes a memory leak in the target memory and the number of times the memory leak occurs based on the number of memory allocations and the number of memory releases, thereby saving processor resources.

[0019] In a possible implementation, the memory usage count information includes a difference between the number of memory allocations and the number of memory releases.

[0020] In this way, whether the target process causes a memory leak in the target memory and the number of times the memory leak occurs can be determined by only one value, thereby saving processor resources.

[0021] In a possible implementation, the memory leak condition includes that the difference value is greater than 0.

[0022] In this way, whether the target process causes a memory leak in the target memory and the number of memory leaks can be determined based on the difference between the number of memory allocations and the number of memory releases, thereby saving processor resources.

[0023] In a possible implementation, the memory usage count information is updated based on a memory allocation instruction for the target memory sent by the target process, and the memory usage count information is updated based on a memory release instruction for the target memory sent by the target process.

[0024] In this way, the number of memory allocations and the number of memory releases can be updated in real time, and the numerical values ​​can be used to determine whether the target process causes a memory leak in the target memory and the number of times the memory leak occurs.

[0025] In a possible implementation, after the occurrence of a target trigger event is detected, function information of the function running in the target process during the statistical process may be output, where the function information at least includes the function name.

[0026] Specifically, the function information of the function that sends the memory allocation instruction and the function information of the function that sends the memory release instruction in the target process during the statistical process can be output, or the function information of all functions running in the target process during the statistical process can be output, and the functions that send the memory allocation instruction and the memory release instruction can be marked. The function information can also include the function name of the upper-level function that calls the function, and the function name of the lower-level function called by the function, etc.

[0027] In this way, technicians can further analyze which specific function the memory leak occurred when running based on the output function information, and accurately locate the cause of the memory leak.

[0028] In a second aspect, a device for detecting memory leaks is provided, which is used to implement the method provided by the above-mentioned first aspect and its possible implementation manners.

[0029] In a third aspect, a computer device is provided, the computer device comprising a memory and a processor, the memory being used to store computer instructions. The processor executes the computer instructions stored in the memory, so that the computer device executes the method provided in the first aspect and possible implementations thereof.

[0030] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program code. When the computer program code is executed by a computer device, the computer device executes the method provided by the first aspect and its possible implementation methods.

[0031] In a fifth aspect, a computer program product is provided. The computer program product includes a computer program code. When the computer program code is executed by a computer device, the computer device executes the method provided by the first aspect and its possible implementation methods. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 is a structural schematic diagram of a computer device provided by an embodiment of the present disclosure;

[0033] Figure 2 It is a flowchart of a method for detecting memory leaks provided by an embodiment of the present disclosure;

[0034] Figure 3 is a schematic diagram of a main interface of a detection application provided by an embodiment of the present disclosure;

[0035] Figure 4 is a schematic diagram of a processing flow for detecting a function causing a memory leak provided by an embodiment of the present disclosure;

[0036] Figure 5 It is a structural schematic diagram of a memory leak detection device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0037] The disclosed embodiments provide a method for detecting memory leaks, which can be implemented by a computer device. The computer device can be a device used by a unit that has a need to detect memory leaks, for example, the unit can be a company that develops an application program and needs to detect whether the application program causes memory leaks. The computer device can be a terminal, server, or server group set in a computer room or office of the above-mentioned units.

[0038] From the hardware composition point of view, such as Figure 1 As shown, the computer device may include a processor 110 , a memory 120 , a communication component 130 , and a display component 140 .

[0039] The processor 110 may be any one or more of a CPU, an NPU, a GPU, etc. The processor 110 may be used to process data information involved in the method, for example, to process allocation events and release events of a target memory.

[0040] The memory 120 may include various volatile memories or non-volatile memories, such as a solid state disk (SSD), a dynamic random access memory (DRAM), etc. The memory 120 may be used to store pre-stored data, intermediate data, and result data in processing, for example, to store memory usage count information, etc.

[0041] The communication component 130 may be a wired network connector, a wireless fidelity (WiFi) module, a Bluetooth module, a cellular network communication module, etc. The communication component 130 may be used to transmit data with other devices, and the other devices may be a service server, etc. For example, sending the detection result of a memory leak, etc.

[0042] The display component 140 can be an independent screen, or a screen integrated with the user device body, a projector, etc. The screen can be a touch screen or a non-touch screen (which can be displayed remotely). The display component 140 is used to display an interface indicating an operation, for example, displaying the main interface of a detection application, etc.

[0043] In addition to the processor, memory, communication component and display component, the host node may also include an audio collection component, an audio output component, etc. The audio collection component may be a microphone for collecting the voice of the technician. The audio output component may be a speaker, earphones, etc. for playing instructions.

[0044] In computer equipment, during the operation of an application, it may need to occupy memory resources managed by the CPU, or it may need to occupy memory resources managed by heterogeneous computing hardware such as NPU and GPU. The memory managed by the CPU is generally set on the motherboard, and is generally also called system memory; the memory managed by the NPU is generally set on the computing card to which the NPU belongs, which can be referred to as computing card memory; the memory managed by the GPU is generally set on the graphics card, and is generally also called display memory. An application can apply for memory resources from the corresponding processor, and after using the memory resources, the corresponding memory resources can be released. The application and release of memory are the responsibility of the corresponding code in the application. However, if the programmer forgets to write the code to release the memory when writing the program code of the application, it will cause a memory leak during the operation of the application.

[0045] The embodiment of the present disclosure provides a method for detecting memory leaks. The embodiment of the present disclosure takes the computing card memory (ie, the memory managed by the NPU) as an example to describe the solution in detail, and other situations are similar and will not be described in detail.

[0046] In addition, the method can be executed by a system program, or by an application for detecting memory leaks. The embodiment of the present disclosure uses this application as an example to explain the solution in detail, and other similar situations will not be repeated.

[0047] like Figure 2 As shown, the method may include the following steps:

[0048] 201 , based on the allocation event and release event of the target memory initiated by the target process, count the memory usage count information of the target memory by the target process.

[0049] Among them, the target memory is the memory managed by the target processor. The target processor is a central processing unit, a neural network processor or a graphics processor. When the target processor is a central processing unit, the target memory is the system memory, when the target processor is a neural network processor, the target memory is the computing card memory, and when the target processor is a graphics processor, the target memory is the display memory. The embodiment of the present disclosure takes the target memory as the computing card memory (i.e., the memory managed by the NPU) as an example to explain the solution in detail, and other situations are similar and will not be repeated.

[0050] When a technician is testing an application (which may be referred to as a target application), he or she may start the above-mentioned application for detecting memory leaks (which may be referred to as a detection application). Figure 3 As shown, a memory selection bar, an application selection bar, a start detection control, etc. may be provided in the main interface of the detection application.

[0051] The technician clicks the memory selection bar to trigger the display of the first drop-down list, which is a memory selection list, in which memories managed by different processors can be displayed, for example, system memory (i.e., memory managed by the CPU), memory managed by the GPU, memory managed by the NPU, etc. The technician can click to select the target memory.

[0052] The technician clicks the application selection bar to trigger the display of the second drop-down list, which is an application selection list for selecting the target application to be tested. The list displays various applications currently installed on the computer device, such as image processing applications, music applications, shopping applications, communication applications, etc. The technician can click to select the target application.

[0053] After the technician clicks the Start Detection control, the detection application starts to monitor the instructions sent by the target application to the system program. It can mainly monitor memory allocation instructions and memory release instructions. In addition, it can also detect some other instructions related to business processing. The detection application can call the system program interface to send monitoring instructions to the target application. When the system program receives the relevant instructions from the target application, it will notify the detection application of the complete content of the instruction or the relevant information in the instruction.

[0054] After starting the detection application, the technician can operate on the computer device to start the target application, which will trigger the computer device to start the corresponding process, namely the target process. The technician can perform any operation in the target application, for example, click on various controls in the target application, enter text in the input box of the target application, and drag a certain operation bar in the target application. Alternatively, the operation of the target application can also be automatically controlled by a preset script, and the operations performed are similar to the above examples. The operations that can be performed depend on the settings in the target application, and the script can be set by the technician. The above-mentioned manual operations or the operations automatically performed by the script may include the operations corresponding to all functions in the target application, or may only include some functions in the target application, which may involve memory allocation and release, and the functions that do not involve memory allocation and release may not be tested.

[0055] When the target application is performing the above operations, the target process may need to initiate one or more allocation events and release events for the target memory.

[0056] Before executing a certain task, the target application needs to apply for a certain amount of computing card memory, and can send a memory allocation instruction for the computing card memory to the system program. Generally, after the target application sends the memory allocation instruction to the system program, the system program sends the memory allocation instruction to the computing card driver, and the computing card driver sends the memory allocation instruction to the NPU on the computing card. The NPU executes the memory allocation instruction to allocate a specified capacity of computing card memory to the target process. After receiving the memory allocation instruction sent by the target application, the system program can notify the detection application, and the detection application can update the memory usage count information. In the case where the memory usage count information includes the number of memory allocations and the number of memory releases, the update process can be to increase the number of memory allocations by a unit number of times (for example, increase by 1). In the case where the memory usage count information includes the difference between the number of memory allocations and the number of memory releases, the update process can be to increase the difference between the number of memory allocations and the number of memory releases by a unit number of times (for example, increase by 1).

[0057] For example, the target application is an application for image recognition. When an image is recognized, the system program receives a memory allocation instruction sent by the target application and can notify the detection application. The detection application can update the memory usage count information and increase the memory allocation count by 1.

[0058] For another example, the target application is an application that performs text recognition. When performing text recognition on a picture, the system program receives the memory allocation instruction sent by the target application and can notify the detection application. The detection application can update the memory usage count information and increase the difference between the memory allocation count and the memory release count by 1.

[0059] After completing a certain task, the target application can apply to release the computing card memory and send a memory release instruction to the system program. Generally, after the target application sends the memory release instruction to the system program, the system program sends the memory release instruction to the computing card driver, and the computing card driver sends the memory release instruction to the NPU on the computing card. The NPU executes the memory release instruction to release the computing card memory allocated when completing this task. After receiving the memory release instruction sent by the target application, the system program can notify the detection application, and the detection application can update the memory usage count information. In the case where the memory usage count information includes the number of memory allocations and the number of memory releases, the update process can be to increase the number of memory releases by a unit number of times (for example, increase by 1). In the case where the memory usage count information includes the difference between the number of memory allocations and the number of memory releases, the update process can be to reduce the difference between the number of memory allocations and the number of memory releases by a unit number of times (for example, reduce by 1).

[0060] For example, the target application is an application for image recognition. After completing the image recognition of an image, the system program receives the memory release instruction sent by the target application and can notify the detection application. The detection application can update the memory usage count information and increase the memory release count by 1.

[0061] For another example, the target application is an application that performs text recognition. After completing text recognition of an image, the system program receives a memory release instruction sent by the target application and can notify the detection application. The detection application can update the memory usage count information and reduce the difference between the memory allocation count and the memory release count by 1.

[0062] 202, a target triggering event is detected.

[0063] The target triggering event includes receiving a memory leak detection instruction.

[0064] When the technician wants to check whether the target application causes a memory leak in the target memory, he can click the End Detection control in the main interface of the detection application. At this time, the detection application detects the occurrence of the target trigger event and then determines whether the memory usage count information meets the memory leak condition.

[0065] In addition, the target trigger event may also be the detection that the target process is idle for a time period exceeding a time threshold, such as half an hour, one hour, etc. The target trigger event may also be the reaching of a specified time point, which may be preset by a technician and may be set to any time point in the idle period, such as 2 a.m., etc.

[0066] 203, if the memory usage count information satisfies the memory leak condition, the target process is output to cause a memory leak in the target memory.

[0067] Among them, memory leak conditions can have multiple possibilities:

[0068] Possibility one: when the memory usage count information includes the number of memory allocations and the number of memory releases, the memory leak condition includes that the number of memory allocations is greater than the number of memory releases.

[0069] If the memory usage count information does not meet the memory leak condition, "The number of memory allocations and the number of memory releases are equal, and there is no memory leak" can be displayed on the interface that displays whether the target process causes a memory leak in the target memory. If the memory usage count information meets the memory leak condition, "The number of memory allocations and the number of memory releases are not equal, and there is a memory leak" can be displayed on the interface that displays whether the target process causes a memory leak in the target memory. In addition, a small window can be displayed on the interface to prompt the technician to further determine when running which specific function the memory leak occurs.

[0070] For example, the target application is an application for image recognition. When recognizing an image, it needs to send 5 memory allocation instructions, and correspondingly, it needs to send 5 memory release instructions. However, the number of memory allocations recorded in the log file is 5 and the number of memory releases is 4. The number of memory allocations is greater than the number of memory releases, which meets the memory leak condition.

[0071] Possibility two: when the memory usage count information includes the difference between the number of memory allocations and the number of memory releases, the memory leak condition includes that the difference is greater than 0.

[0072] If the memory usage count information does not meet the memory leak condition, "The number of memory allocations and the number of memory releases are equal, and there is no memory leak" can be displayed on the interface that displays whether the target process causes a memory leak in the target memory. If the memory usage count information meets the memory leak condition, "The number of memory allocations and the number of memory releases are not equal, and there is a memory leak" can be displayed on the interface that displays whether the target process causes a memory leak in the target memory. In addition, a small window can be displayed on the interface to prompt the technician to further determine when running which specific function the memory leak occurs.

[0073] For example, the target application is an application for text recognition. When performing text recognition on a picture, it needs to send 5 memory allocation instructions, and correspondingly, it needs to send 5 memory release instructions. However, the difference between the number of memory allocations and the number of memory releases recorded in the log file is 1, which is greater than 0, satisfying the memory leak condition.

[0074] Output the function information of the function running in the target process during the statistical process, and the function information at least includes the function name. Specifically, the function information of the function that sends the memory allocation instruction and the function that sends the memory release instruction in the target process during the statistical process can be output, or the function information of all functions running in the target process during the statistical process can be output, and the functions that send the memory allocation instruction and the memory release instruction can be marked. The function information can also include the function name of the upper-level function that calls the function, and the function name of the lower-level function called by the function, etc.

[0075] After the technician clicks the memory leak detection control, the detection application can determine whether the memory usage count information meets the memory leak condition and obtain the memory leak detection result. The detection application can display a sub-interface with the memory leak detection result. The memory leak detection result may include whether the memory leak condition is met, the final statistical memory usage count information, the function name of each function (which can be called the target function) running in the target process during the detection process, the call relationship between the running target functions, the function that applies for memory, the function that releases memory, etc. "Whether the memory leak condition is met" can be used by the technician to confirm whether a memory leak occurs. "Finally statistical memory usage count information" can be used by the technician to understand the specific leakage situation, and how many times the memory applied was not released normally. "The function name of each function running in the target process during the detection process" can be used by the technician to roughly understand the function that may cause memory leaks. "The call relationship between the running target functions", "the function that applies for memory", and "the function that releases memory" can be used by the technician to further analyze the function that may cause memory leaks.

[0076] The contents included in the memory leak detection results can be pre-set by a technician, and corresponding setting options can be set in the detection application for the technician to operate and set.

[0077] In the embodiment of the present disclosure, after detecting the occurrence of a target trigger event, it is also possible to detect when a specific function is running and a memory leak occurs. The corresponding processing flow can be as follows: Figure 4 As shown, the following steps are included:

[0078] 401, It is determined that the target process causes a memory leak in the target memory.

[0079] When the technician finds that the target process causes a memory leak in the target memory on the memory leak detection result interface, the technician can further detect which specific function the memory leak occurs when running. When the memory leak detection result interface shows that there is a memory leak, a small window can be displayed. This small window can include a control for detecting the function where the memory leak occurs. The technician can click on the control to trigger the computer device to start detecting which specific function the memory leak occurs when running.

[0080] 402. Set the function set corresponding to the target process as the function set to be tested.

[0081] The set of functions to be tested can be pre-set by the technician, and can be all the functions running in the target process, or functions related to memory allocation and release selected by the technician based on experience. Alternatively, after the technician clicks on the control to detect the function where a memory leak occurs, a pop-up window may pop up. The pop-up window may contain the function names of the functions running in the target process, or the function names of all pre-stored functions corresponding to the target process. The technician can click on the function names of the functions he wants to test and set these functions as the set of functions to be tested.

[0082] 403. Select some functions from the set of functions to be tested as target functions.

[0083] There are several ways to select some functions from the set of functions to be tested:

[0084] Method 1, automatic selection: The number of functions in the set of functions to be tested can be divided by 2 and then rounded up to determine the number N of target functions. Then, the detection application can randomly select from the set of functions to be tested, or select from front to back according to the preset order of each function to obtain the target function.

[0085] Method 2: manual selection: A target function selection bar can be displayed in the detection application. When the technician clicks the target function selection bar, a third drop-down list can be triggered. The third drop-down list can display the function names of all functions in the function set to be tested. The technician can click one or more function names in the third drop-down list, and the detection application can set the function corresponding to the selected function name as the target function.

[0086] 404, restart the target process, execute the target function, and based on the allocation events and release events of the target memory initiated by the target process, count the memory usage count information of the target process on the target memory. When a target trigger event is detected, determine whether the currently counted memory usage count information meets the memory leak condition. If the memory usage count information meets the memory leak condition, execute step 405. If the memory usage count information does not meet the memory leak condition, execute step 406.

[0087] After determining the target function, the detection application can instruct the operating system to restart the target process, execute the target function, and record the memory usage count information when executing the target function. The process of determining whether the currently counted memory usage count information meets the memory leak condition is similar to the above step 203 and will not be repeated here.

[0088] There are several ways to implement the objective function:

[0089] Method 1: Automatic execution: The detection application can pre-store the correspondence between each function and operation control in the target application. After restarting the target process, the detection application can automatically operate the target operation control corresponding to the target function based on the correspondence to trigger the execution of the target function.

[0090] Method 2: Manual operation and execution: After restarting the target process, a pop-up window may be displayed, which may display the function name of the target function and the corresponding operation control. The technician may refer to the prompt content in the pop-up window and click the operation control in the target application to trigger the execution of the target function.

[0091] 405. Restart the target process, execute other functions in the set of functions to be tested except the target function, and based on the allocation events and release events of the target memory initiated by the target process, count the memory usage count information of the target process on the target memory. When a target trigger event is detected, determine whether the currently counted memory usage count information meets the memory leak condition. If the memory usage count information meets the memory leak condition, execute step 403 (reselect some functions as target functions). If the memory usage count information does not meet the memory leak condition, execute step 407.

[0092] After determining that the memory usage count information of the target function meets the memory leak condition, the detection application can instruct the operating system to restart the target process, execute other functions in the set of functions to be tested except the target function, and record the memory usage count information when executing the above functions. The process of determining whether the currently counted memory usage count information meets the memory leak condition is similar to the above step 203 and will not be repeated here.

[0093] There are multiple ways to execute the above function:

[0094] Method 1: Automatic execution: The detection application can pre-store the correspondence between each function and operation control in the target application. After restarting the target process, the detection application can automatically operate the target operation control corresponding to the above function based on the correspondence to trigger the execution of the above function.

[0095] Method 2: Manual operation execution: After restarting the target process, a pop-up window can be displayed, which can display the function name of the target function and the corresponding operation control. The technician can refer to the prompt content in the pop-up window and click the operation control in the target application to trigger the execution of the function corresponding to the operation control.

[0096] 406 , determining whether the number of functions other than the target function in the test set is 1, if the number of functions in the test set is 1, executing step 408 , if the number of functions in the test set is not 1, executing step 409 .

[0097] 407 , determine whether the number of functions of the target function in the set to be tested is 1. If the number of functions in the set to be tested is not 1, execute step 4010 ; if the number of functions in the set to be tested is 1, execute step 4011 .

[0098] 408, output the function names of other functions.

[0099] When the detection application is performing detection, the interface may display "Detecting". When the detection application is completed, the function names of other functions may be displayed in the interface. When the technician clicks on the function name, the complete code of the function can be seen.

[0100] The technician can modify the function based on the output.

[0101] 409 , setting the other functions in the set of functions to be tested except the target function as the set of functions to be tested, and executing step 403 .

[0102] 4010, set the target function as the set of functions to be tested, and execute step 403.

[0103] 4011, output the function name of the target function.

[0104] When the detection application is performing detection, the interface may display "Detecting". When the detection application is completed, the function name of the target function may be displayed in the interface. When the technician clicks on the function name, he can see the complete code of the function.

[0105] The technician can modify the function based on the output.

[0106] In addition, when the set of functions to be tested does not change after N consecutive cycles to step 403, the cycle ends and the function names of all functions in the current set of functions to be tested are output.

[0107] In most cases, there is only one function in the application that causes a memory leak. When executing the above process, the function that causes the memory leak can be determined when executing steps 406 and 407. In a few cases, there may be multiple functions that cause memory leaks. In this case, after the process has been looped for several times, all functions included in the set of functions to be tested are the multiple functions that cause memory leaks. Thereafter, the process will continuously loop to execute steps 403-405. Based on the above settings, when the set of functions to be tested does not change after N consecutive loops to step 403, the loop ends and the function names of all functions in the current set of functions to be tested are output.

[0108] By using this method, it is possible to determine whether the target process causes a memory leak in the target memory through simple memory usage statistics. There is no need to count the total amount of memory requested and released. Simpler statistical calculations replace more complex statistical calculations, saving a lot of processor resources.

[0109] Based on the same technical concept, the embodiment of the present disclosure provides a device for detecting memory leaks, such as Figure 5 As shown, the device comprises:

[0110] The statistics module 510 is used to count the memory usage count information of the target process on the target memory based on the allocation event and release event of the target memory initiated by the target process, wherein the target memory is the memory managed by the target processor. Specifically, the processing functions of the above steps 201, 404, 405 and other implicit steps can be realized.

[0111] The detection module 520 is used to detect the occurrence of a target triggering event, and can specifically implement the processing functions of the above steps 202 and 404, as well as other implicit steps.

[0112] The output module 530 is used to output the target process causing the target memory to leak memory if the memory usage count information meets the memory leak condition. Specifically, it can realize the processing functions of the above steps 203, 408, 4011, and other implicit steps.

[0113] In a possible implementation manner, the target triggering event includes receiving a memory leak detection instruction.

[0114] In one possible implementation, the target processor is a central processing unit, a neural network processor, or a graphics processor.

[0115] In a possible implementation, the memory usage count information includes the number of memory allocations and the number of memory releases.

[0116] In a possible implementation, the memory leak condition includes that the number of memory allocations is greater than the number of memory releases.

[0117] In a possible implementation, the memory usage count information includes a difference between the number of memory allocations and the number of memory releases.

[0118] In a possible implementation, the memory leak condition includes that the difference value is greater than 0.

[0119] In a possible implementation, the statistics module 510 is used to update the memory usage count information based on the memory allocation instruction sent by the target process to the target memory, and update the memory usage count information based on the memory release instruction sent by the target process to the target memory. Specifically, the processing function of the above step 201 and other implicit steps can be implemented.

[0120] In a possible implementation, the output module 530 is further used to: output function information of the function running in the target process during the statistical process, the function information at least including the function name. Specifically, the processing functions of the above steps 203, 408, 4011 and other implicit steps can be implemented.

[0121] The statistical module 510, the detection module 520, and the output module 530 may be implemented by a processor, or by a processor in conjunction with a memory and a communication component.

[0122] By using the above device, it is possible to determine whether the target process causes a memory leak in the target memory through simple memory usage statistics. There is no need to count the total amount of memory requested and released. Simpler statistical calculations replace more complex statistical calculations, saving a lot of processor resources.

[0123] The memory leak detection device provided in the above embodiment only uses the division of the above functional modules as an example when detecting memory leaks. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the user equipment is divided into different functional modules to complete all or part of the functions described above. In addition, the memory leak detection device provided in the above embodiment and the memory leak detection method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0124] The embodiments of the present disclosure also provide a computer-readable storage medium. The computer-readable storage medium may be any available medium that can be stored by a computing device or a data storage device such as a data center that includes one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a digital video disk (DVD)), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct a computing device to perform a business processing method, or instructs a computing device to perform a business processing method.

[0125] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present disclosure.

Claims

1. A method for detecting memory leaks, characterized in that: The method comprises: Based on the allocation event and release event of the target memory initiated by the target process, counting the memory usage count information of the target memory by the target process, wherein the target memory is the memory managed by the target processor; A target triggering event is detected; If the memory usage count information satisfies a memory leak condition, outputting the target process causes a memory leak to occur in the target memory.

2. The method according to claim 1, characterized in that The target triggering event includes receiving a memory leak detection instruction.

3. The method according to claim 1 or 2, characterized in that: The target processor is a central processing unit, a neural network processor or a graphics processor.

4. The method according to any one of claims 1 to 3, characterized in that: The memory usage count information includes the number of memory allocations and the number of memory releases.

5. The method according to claim 4, characterized in that The memory leak condition includes that the number of memory allocations is greater than the number of memory releases.

6. The method according to any one of claims 1 to 3, characterized in that: The memory usage count information includes the difference between the number of memory allocations and the number of memory releases.

7. The method according to claim 6, characterized in that The memory leak condition includes the difference being greater than zero.

8. The method according to any one of claims 1 to 7, characterized in that: The method of counting memory usage count information of the target memory by the target process based on the allocation event and release event of the target memory initiated by the target process includes: Based on a memory allocation instruction for a target memory sent by the target process, memory usage count information is updated; and based on a memory release instruction for a target memory sent by the target process, memory usage count information is updated.

9. The method according to any one of claims 1 to 8, characterized in that: After the target triggering event is detected, the method further includes: Output function information of the function running in the target process during the statistical process, wherein the function information at least includes the function name.

10. A device for detecting memory leaks, characterized in that: The device comprises: A statistics module, configured to count memory usage count information of the target process on the target memory based on allocation events and release events of the target memory initiated by the target process, wherein the target memory is memory managed by the target processor; A detection module, used for detecting the occurrence of a target triggering event; The output module is used for outputting that the target process causes the target memory to leak if the memory usage count information meets the memory leak condition.

11. The device according to claim 10, characterized in that The target triggering event includes receiving a memory leak detection instruction.

12. The device according to claim 10 or 11, characterized in that The target processor is a central processing unit, a neural network processor or a graphics processor.

13. The device according to any one of claims 10 to 12, characterized in that: The memory usage count information includes the number of memory allocations and the number of memory releases.

14. The device according to claim 13, characterized in that The memory leak condition includes that the number of memory allocations is greater than the number of memory releases.

15. The device according to any one of claims 10 to 12, characterized in that: The memory usage count information includes the difference between the number of memory allocations and the number of memory releases.

16. The device according to claim 15, characterized in that The memory leak condition includes the difference being greater than zero.

17. The device according to any one of claims 10 to 16, characterized in that: The statistics module is used to: Based on the memory allocation instruction for the target memory sent by the target process, the memory usage count information is updated, and based on the memory release instruction for the target memory sent by the target process, the memory usage count information is updated.

18. The device according to any one of claims 10 to 17, characterized in that: Output modules are also used to: Output function information of the function running in the target process during the statistical process, wherein the function information at least includes the function name.

19. A computer device, characterized in that: The computer device comprises a memory and a processor, wherein the memory is used to store computer instructions; The processor executes the computer instructions stored in the memory to enable the computer device to perform the method according to any one of claims 1 to 9.

20. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program code. When the computer program code is executed by a computer device, the computer device executes the method according to any one of claims 1 to 9.