CN110795355A - Method and device for detecting memory leakage - Google Patents

Method and device for detecting memory leakage Download PDF

Info

Publication number
CN110795355A
CN110795355A CN201911048075.6A CN201911048075A CN110795355A CN 110795355 A CN110795355 A CN 110795355A CN 201911048075 A CN201911048075 A CN 201911048075A CN 110795355 A CN110795355 A CN 110795355A
Authority
CN
China
Prior art keywords
memory
program
information
unreleased
leak
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201911048075.6A
Other languages
Chinese (zh)
Inventor
张�雄
胡志豪
孙传景
李丹丹
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sonoscape Medical Corp
Original Assignee
Sonoscape Medical Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Sonoscape Medical Corp filed Critical Sonoscape Medical Corp
Priority to CN201911048075.6A priority Critical patent/CN110795355A/en
Publication of CN110795355A publication Critical patent/CN110795355A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/366Software debugging using diagnostics
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3644Software debugging by instrumenting at runtime

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application provides a method and a device for detecting memory leakage, which are applied to a memory leakage detection tool, wherein the memory leakage detection tool is linked with a program, and the method comprises the following steps: in the process of program operation, according to the conditions of memory application and release, recording the memory information of the unreleased memory; generating a periodic memory leak report according to a preset period; after the program is operated, analyzing code information causing memory leakage in the program according to the memory information of unreleased memories in the generated multiple periodic memory leakage reports; the code causing memory leakage in the program is the code which does not release the memory and increases along with the increase of the running times of the code; and generating a final memory leak report. According to the method and the device, codes which are increased along with the increase of the running times of the codes and do not cause memory leakage in the program can be analyzed according to the multiple staged memory leakage reports, so that the codes which cause the memory leakage do not need to be analyzed manually, and the efficiency of detecting the memory leakage is improved.

Description

Method and device for detecting memory leakage
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for detecting memory leakage.
Background
A memory leak is when a dynamically allocated heap memory in a program is not released or cannot be released by the program for some reason. The memory leak will cause the waste of system memory, resulting in the serious consequences such as the slow running speed of the program and even the system crash. In the prior art, an open source tool is mainly adopted for memory leak detection. Specifically, the open source tool records memory information in the program running process, and records the memory information of the unreleased memory.
However, the memory information recorded by the source-opening tool that is not released memory is not necessarily caused by memory leakage, and may be resident memory with a longer life cycle. Therefore, in the conventional memory leak detection method, it is necessary to manually analyze the memory information of the unreleased memory recorded by the open source tool to find out the true memory leak point. Because the existing memory leak detection method needs to manually analyze codes with memory leaks in programs, the consumed energy is large, and the efficiency of memory leak detection is not high.
Disclosure of Invention
Based on the defects of the prior art, the application provides a method and a device for detecting memory leakage, so that codes causing memory leakage in a program can be automatically analyzed, and the efficiency of detecting memory leakage is improved.
The invention discloses a method for detecting memory leakage, which is applied to a memory leakage detection tool, wherein the memory leakage detection tool is linked with a program, and the method for detecting memory leakage comprises the following steps:
in the process of running the program, recording the memory information of the unreleased memory according to the memory application and release conditions;
generating a periodic memory leak report according to a preset period; wherein the periodic memory leak report includes memory information of unreleased memory recorded by the memory leak detection tool;
after the program is operated, analyzing code information causing memory leakage in the program according to memory information of unreleased memories in the generated multiple periodic memory leakage reports; wherein, the codes causing memory leak in the program are codes which do not release memory and increase along with the increase of the running times of the codes in the multi-share staged memory leak report;
generating a final memory leak report; wherein the memory leak report includes information of codes causing memory leaks in the program.
Optionally, in the method for detecting a memory leak, the memory information of the unreleased memory includes: address information of the unreleased memory, memory size information of the unreleased memory, and stack address information called when the unreleased memory is applied;
the code information causing the memory leak in the program comprises: address information of an unreleased memory applied by a code causing memory leakage in the program, memory size information of the unreleased memory applied by the code causing memory leakage in the program, and line number information of the code causing memory leakage in the program.
Optionally, in the method for detecting a memory leak, before recording the memory information of the unreleased memory according to the memory application and the memory release condition, the method further includes:
triggering a driving module of the program, enabling the driving module to read a test case file, and controlling the program to execute an operation corresponding to the test case file according to the test case file; and the test case file comprises the operation which needs to be executed by the program.
Optionally, in the method for detecting a memory leak, the program is an ultrasonic detection program;
wherein the test case file comprises: fields corresponding to operational flow in different modes of the ultrasound detection program; and fields in the test case file, which correspond to the operation streams in different modes of the ultrasonic detection program, can be edited and adjusted.
Optionally, in the method for detecting a memory leak, after triggering the driver module of the program, the method further includes:
receiving a starting instruction sent by the driving module; the starting instruction is used for controlling the memory leak detection tool to start to execute the operation of recording the memory information of the unreleased memory;
receiving an ending instruction sent by the driving module; the ending instruction is used for controlling the memory leak detection tool to end the operation of recording the memory information of the unreleased memory; and the ending instruction is sent out after the drive module finishes reading the test case file.
Optionally, in the method for detecting a memory leak, the triggering the driver module of the program includes:
and triggering the drive module of the program by calling a function interface corresponding to the drive module of the program.
Optionally, in the method for detecting a memory leak, the memory leak detection tool is a linkable library file, and the memory leak detection tool is bound to a device running the program.
The second aspect of the present invention discloses a device for detecting memory leak, which is applied to a memory leak detection tool, wherein the memory leak detection tool is linked with a program, and the device for detecting memory leak includes:
the recording unit is used for recording the memory information of the unreleased memory according to the memory application and release conditions in the program running process;
the first generating unit is used for generating a periodic memory leakage report according to a preset period; wherein, the periodic memory leak report includes the memory information of the unreleased memory recorded by the recording unit;
the analysis unit is used for analyzing code information causing memory leakage in the program according to the memory information of the unreleased memory in the multiple sets of staged memory leakage reports generated by the first generation unit after the program operation is finished; wherein, the codes causing memory leak in the program are codes which do not release memory and increase along with the increase of the running times of the codes in the multi-share staged memory leak report;
the second generating unit is used for generating a final memory leak report; wherein the memory leak report includes information of codes causing memory leaks in the program.
Optionally, in the apparatus for detecting a memory leak, the memory information of the unreleased memory includes: address information of the unreleased memory, memory size information of the unreleased memory, and stack address information called when the unreleased memory is applied;
the code information causing the memory leak in the program comprises: address information of an unreleased memory applied by a code causing memory leakage in the program, memory size information of the unreleased memory applied by the code causing memory leakage in the program, and line number information of the code causing memory leakage in the program.
Optionally, the apparatus for detecting a memory leak further includes:
the triggering unit is used for triggering the driving module of the program, enabling the driving module to read the test case file and controlling the program to execute the operation corresponding to the test case file according to the test case file; and the test case file comprises the operation which needs to be executed by the program.
Optionally, in the device for detecting a memory leak, the program is an ultrasonic detection program;
wherein the test case file comprises: fields corresponding to operational flow in different modes of the ultrasound detection program; and fields in the test case file, which correspond to the operation streams in different modes of the ultrasonic detection program, can be edited and adjusted.
Optionally, the apparatus for detecting a memory leak further includes:
the first receiving unit is used for receiving a starting instruction sent by the driving module; the starting instruction is used for controlling the recording unit to start to execute the operation of recording the memory information of the unreleased memory;
the second receiving unit is used for receiving an ending instruction sent by the driving module; the ending instruction is used for controlling the recording unit to end the operation of recording the memory information of the unreleased memory; and the ending instruction is sent out after the drive module finishes reading the test case file.
Optionally, in the apparatus for detecting a memory leak, when the triggering unit executes a driving module that triggers the program, the triggering unit is configured to:
and triggering the drive module of the program by calling a function interface corresponding to the drive module of the program.
Optionally, in the apparatus for detecting a memory leak, the memory leak detection tool is a linkable library file, and the memory leak detection tool is bound to a device running the program.
According to the technical scheme, the memory leak detection method is applied to the memory leak detection tool, and in the program running process, the memory leak detection tool records the memory information of the unreleased memory according to the memory application and release conditions. And generating a periodic memory leak report according to a preset period. Wherein the periodic memory leak report includes the recorded memory information of the unreleased memory. After the program is operated, analyzing code information causing memory leakage in the program according to the memory information of the unreleased memory in the generated multi-copy staged memory leakage report. The codes causing the memory leak in the program are codes, in the multi-stage memory leak report, of which the unreleased memory increases along with the increase of the running times of the codes. And then regenerating the final memory leak report. The final memory leak report includes information of the code causing the memory leak in the program. The memory leak detection tool can analyze codes of unreleased memories in a program, which are increased along with the increase of the running times of the codes, according to the memory information of the unreleased memories in the generated multiple staged memory leak reports, and does not need to manually analyze the codes causing the memory leak in the program, so that the memory leak detection efficiency is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a schematic flow chart illustrating a method for detecting memory leakage according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a device for detecting memory leakage according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, the embodiment of the present application discloses a method for detecting a memory leak, which is applied to a memory leak detection tool. Wherein the memory leak detection tool is linked to the program. The memory leak detection tool is a dynamically linked library file, and when a program linked with the library file is executed, the corresponding library file is called. Specifically, the method for detecting a memory leak shown in fig. 1 includes:
and S101, in the process of program operation, recording the memory information of the unreleased memory according to the memory application and the release condition.
The program in step S101 may be executed in an electronic device, which may be a computer, a mobile terminal, a medical device, or the like. And binding the memory leak detection tool with the electronic equipment to realize the linkage with the program in the electronic equipment. Alternatively, the memory leak detection tool may be a dynamically linked library file, and when a program linked to the library file is executed, the corresponding library file is called.
The program may be any program and may have tasks that need to be performed by itself. For example, it may be a program for ultrasonic inspection, it may be a program for image processing, it may be a game program, and the like. However, if the codes in the program are manually checked to find out the codes causing the memory leaks and corresponding debugging is performed, it obviously takes a lot of time and effort, so in the present application, the memory leak detection tool is linked with the program, and the memory leak detection tool is used to perform the memory leak detection on the program.
Because the memory leak detection tool is linked with the program, the memory leak detection tool is called in the running process of the program, and the memory information of the unreleased memory is recorded when the program executes memory application and release. Specifically, when a program executes a memory request, the memory leak detection tool records memory information of the memory requested by the program, for example, in a specific table. Optionally, the memory leak detection tool may record the memory information of the application memory by means of library piling. When the program calls the library function, the memory information of the applied memory can be recorded in a table. When the program executes the operation of releasing the memory, the memory leak detection tool deletes the previously recorded corresponding memory information when the memory is applied from the table. Therefore, the memory leak detection tool records only the memory information of the memory that has not been released in the table. It should be noted that the memory leak detection tool may also record the memory information when the memory is applied and the memory information when the memory is released, then obtain the memory information of the unreleased memory by comparing the recorded information, and record the memory information in the periodic memory leak report generated in step S102.
Optionally, the memory information of the unreleased memory includes address information of the unreleased memory, memory size information of the unreleased memory, and stack address information called when the unreleased memory is applied. The address information of the unreleased memory refers to the position information of the unreleased memory block in the memory, and the stack address information called when the unreleased memory is applied corresponds to the code line number information in the program. According to the stack address called when the memory is not released, the application of the memory can be known when the program runs to which line of codes.
Optionally, in a specific embodiment of the present application, before executing step S101, the method further includes:
and triggering a drive module of the program, enabling the drive module to read the test case file, and controlling the program to execute the operation corresponding to the test case file according to the test case file.
The test case file comprises the operation to be executed by the program. Specifically, the test case file includes operation instructions corresponding to a plurality of application scenarios and operation flows corresponding to the respective application scenarios. The driver module can also be considered as a driver, and the driver module reads the field in the test file to drive the driver to perform the corresponding operation. Specifically, after the program is powered on and started, a memory leak detection tool linked with the program is called, and the memory leak detection tool further triggers a drive module of the program, so that the drive module controls the program to execute an operation corresponding to the test case file by reading the test case file.
In the prior art, a program usually needs to manually execute some operation instructions in the running process, and the program automatically runs an operation flow corresponding to the operation instructions after the manually executed operation instructions are obtained, otherwise, the program cannot be continuously run, that is, the program needs to be manually driven by inputting instructions in the running process. For example, the ultrasonic detection program needs to run corresponding processes in different modes, such as a B (grayscale imaging) Mode, a Colorflow (CFM) Mode, and a pulse doppler (PW) Mode, whereas in the prior art, the program needs to be controlled to execute the corresponding operation processes in the different modes by manually selecting and inputting the operation instructions corresponding to the different modes, and specifically, when the program runs to a Mode selection code, the method comprises the steps of executing a program, and executing a program in a mode required to be executed.
In the present application, the test case file includes a plurality of operation instructions. The mode that the drive module reads the operation instruction in the test case file replaces the process of manually inputting the operation instruction in the prior art, so that the automatic operation can be realized without manual interference in the process of program operation, and the efficiency of memory leakage detection is improved.
Optionally, in a specific embodiment of the present application, when the program is an ultrasonic detection program, the test case file includes: fields corresponding to the operational flow in different modes of the ultrasound detection procedure. The fields in the test case file corresponding to the operation flow in different modes of the ultrasonic detection program can be edited and adjusted.
For example, a field corresponding to a gray-scale imaging mode of the ultrasonic detection, a field corresponding to a color blood flow mode of the ultrasonic detection, a field corresponding to a pulse doppler mode of the ultrasonic detection, and the like may be included in the test case file. And writing operation instructions of different modes in the ultrasonic detection program into the test case file, and controlling the program to execute corresponding operation when the drive module reads the B field, the CFM field or the PW field. It should be noted that the test case file may be edited and modified according to actual situations, so as to control a scenario in which the program needs to perform the memory leak detection during the running. When a new application scene is added to the program, the test case file can be edited and modified, and the memory leak detection can be performed on the program added with the new application scene.
Optionally, in an embodiment of the present application, when the memory leak detection tool executes the driver module of the trigger program, the method includes:
and triggering the drive module of the program by the memory leak detection tool through the function interface corresponding to the drive module of the calling program.
Specifically, after the program is powered on and started, the memory leak detection tool is called to start running, and the memory leak detection tool enables the drive module to start running through the function interface corresponding to the drive module of the calling program. And the drive module starts to read the test case file and executes the operation corresponding to the test case file according to the test case file control program.
Optionally, in a specific embodiment of the present application, after triggering the driver module of the program, the method further includes:
and receiving a starting instruction sent by the driving module.
The start instruction is used to control the memory leak detection tool to start executing the operation of recording the memory information of the unreleased memory, that is, the start instruction is used to control the memory leak detection tool to start executing step S101. Specifically, after the memory leak detection tool triggers the driver module of the program, the driver module starts to read the test case file and sends a start instruction to the memory leak detection tool to notify the memory leak detection tool that the program has started to execute various operations in the test case file, so that the memory leak detection tool can start to record the memory application and the memory release condition of the program.
In the prior art, an open source tool is linked with a program, and after the program is started, the open source tool is called, and a code in the open source tool starts to run. However, whether the open source tool starts recording the memory information still needs to be controlled by manually inputting a start instruction. The open source tool only starts to detect the memory leak after receiving a start instruction input manually.
In the application, because the information interaction exists between the driving module and the memory leak detection tool, the driving module can automatically send a start instruction to the memory leak detection tool when the driving module starts to read the test case file, manual intervention is not needed, and the detection efficiency of the memory leak detection tool is further improved.
And S102, generating a periodic memory leak report according to a preset period.
Wherein the periodic memory leak report includes memory information of unreleased memory recorded by the memory leak detection tool. The memory information of the unreleased memory is recorded in step S101. For example, if the program runs for a total of 5 hours, the period is set to 1 hour, that is, one periodic memory leak report is generated every 1 hour of the program running, and 5 periodic memory leak reports are generated in total. That is, the shorter the set period is, the more periodic memory leak reports are generated in total after the program operation is finished. The more the periodic memory leak reports are, the higher the accuracy of the result analyzed by the memory leak detection tool when executing step S103 is, but the more the memory leak reports are, the more the data to be analyzed by the memory leak detection tool when executing step S103 becomes, and the efficiency is reduced. Therefore, the period duration can be set according to actual conditions.
It should be noted that, the only memory information recorded in the periodic memory leak report is the memory information of the unreleased memory, but the unreleased memory is not necessarily caused by the memory leak, and may be a resident memory with a longer life cycle. Therefore, the periodic memory leak report obtained in step S102 still cannot determine the code information causing the memory leak in the program, and step S103 needs to be performed subsequently.
Optionally, in an embodiment of the present application, after the triggering the driver module of the program by the memory leak detection tool, the method further includes:
and receiving an ending instruction sent by the driving module.
The ending instruction is used for controlling the memory leak detection tool to end the operation of recording the memory information of the unreleased memory; and the ending instruction is sent out after the drive module reads the test case file. Specifically, after the memory leak detection tool starts a drive module of the program, the drive module starts to read the test case file, and when the drive module finishes reading the last line of fields in the test case file, an end instruction is sent to the memory leak detection tool to tell the memory leak detection tool that the program calls and releases the memory, and recording is not needed. Further, the memory leak tool is caused to end execution of step S102 and start execution of step S103. In the prior art, after a program runs all application scenes, a manual instruction needs to be input to control an open source tool to finish detection. In the application, the memory leak detection tool interacts with the program drive module, and the drive module can control the memory leak detection tool to finish executing the step S102 by sending a finish instruction, so that automatic control is realized without human intervention, and the detection efficiency of the memory leak detection is further improved.
And S103, after the program operation is finished, analyzing code information causing memory leakage in the program according to the memory information of the unreleased memory in the generated multiple staged memory leakage reports.
The codes causing the memory leak in the program are codes, in the multi-stage memory leak report, of which the unreleased memory increases along with the increase of the running times of the codes. The memory information of the unreleased memory comprises address information of the unreleased memory, memory size information of the unreleased memory, and stack address information called when the unreleased memory is applied.
Specifically, the memory leak detection tool filters out code information causing memory leak in the program from a plurality of staged memory leak reports according to a preset rule. The preset rule may be: the memory leak detection tool finds out that, for the same stack address information, the unreleased memory corresponding to the stack address appears to increase as the program operation time increases by comparing the multiple sets of staged memory leak reports generated in step S102. For example, in the periodic memory leak report generated in the first hour of program operation, one unreleased memory block corresponding to one stack address has one block, and the address is 001, while in the periodic memory leak report generated in the second hour of program operation, there are two unreleased memory blocks corresponding to the stack address, and the addresses are 001 and 002, respectively, that is, during the first hour of program operation, the memory block of 001 is still unreleased, and during the second hour of operation, when the memory leak detection tool calls the stack address again, the memory block of 002 is occupied more. That is, as the running time of the program increases, the number of times of calling the same stack address increases, and the number of the memory blocks which are not released increases, it can be determined that the memory leak occurs. On the contrary, if in the periodic memory leak report generated in the first hour, one unreleased memory block corresponding to one stack address has one block and the address is 001, and in the periodic memory leak report generated in the fifth hour of the program operation, the unreleased memory block corresponding to the stack address still has the memory block number 001, the number of the memory blocks corresponding to the stack address is not increased, and the unreleased memory may be a resident memory, so that there is no memory leak. The stack address information that does not appear in the finally generated staged memory leak report does not necessarily belong to the stack address information causing the memory leak. Because the stack address information corresponds to the code in the program, the code causing the memory leak in the program can be found by analyzing the stack address information causing the memory leak.
It should be noted that, whether the memory leak is serious or not can be determined according to the memory size information of the unreleased memory, and if the memory leak is not considered to be serious, the code causing the memory leak may not be adjusted and modified.
Optionally, in an embodiment of the present application, the code information causing the memory leak in the program includes: address information of an unreleased memory applied by a code causing a memory leak in a program, memory size information of an unreleased memory applied by a code causing a memory leak in a program, and line number information of a code causing a memory leak in a program. The line number information of the code causing memory leakage in the program is obtained from the stack address called when the memory is applied.
In the prior art, the open source tool only generates a memory leak report after the program runs, the generated memory leak report only includes the memory information of the unreleased memory, and subsequently, the code causing the memory leak in the program can be determined only by manually analyzing whether the memory information of the unreleased memory is caused by the memory leak.
In the application, the memory leak detection tool generates the memory leak reports at different stages of program operation, the analysis tool in the memory leak detection tool analyzes the periodic memory leak reports at a plurality of different stages, information caused by memory leak in a memory information system of unreleased memory can be filtered out according to a preset rule, and further the process of analyzing the memory leak does not need manual intervention, so that the efficiency of memory leak detection is improved.
And S104, generating a final memory leakage report.
The final memory leak report includes information of the code causing the memory leak in the program. The code information causing memory leak in the program includes: address information of an unreleased memory applied by a code causing a memory leak in a program, memory size information of an unreleased memory applied by a code causing a memory leak in a program, and line number information of a code causing a memory leak in a program.
The memory leak detection method is applied to a memory leak detection tool, wherein the memory leak detection tool is linked with a program, and in the running process of the program, the memory leak detection tool records memory information of an unreleased memory according to the memory application and release conditions. And generating a periodic memory leak report according to a preset period. Wherein the periodic memory leak report includes the recorded memory information of the unreleased memory. After the program is operated, analyzing code information causing memory leakage in the program according to the memory information of the unreleased memory in the generated multi-copy staged memory leakage report. The codes causing the memory leakage in the program are codes of which the unreleased memory is increased along with the increase of the running times of the codes. And then regenerating the final memory leak report. The final memory leak report includes information of the code causing the memory leak in the program. The memory leak detection tool can analyze codes of unreleased memories in a program, which are increased along with the increase of the running times of the codes, according to the memory information of the unreleased memories in the generated multiple staged memory leak reports, and does not need to manually analyze the codes causing the memory leak in the program, so that the memory leak detection efficiency is improved.
Referring to fig. 2, based on the method for detecting memory leak provided by the embodiment of the present application, the embodiment of the present application further discloses a device 200 for detecting memory leak, which is applied to a memory leak detection tool, wherein the memory leak detection tool is linked with a program, and the device 200 for detecting memory leak includes: recording unit 201, first generating unit 202, analyzing unit 203, and second generating unit 204.
The recording unit 201 is configured to record, in the process of running the program, memory information of a memory that is not released according to the memory application and the release condition.
The first generating unit 202 is configured to generate a periodic memory leak report according to a preset period.
The periodic memory leak report includes memory information of unreleased memory recorded by the recording unit.
The analyzing unit 203 is configured to, after the program operation is finished, analyze, according to the memory information of the unreleased memory in the multiple sets of periodic memory leak reports generated by the first generating unit, code information causing memory leak in the program. The codes causing the memory leak in the program are codes, in the multi-stage memory leak report, of which the unreleased memory increases along with the increase of the running times of the codes.
A second generating unit 204, configured to generate a final memory leak report. The final memory leak report includes information of the code causing the memory leak in the program.
Optionally, in an embodiment of the present application, the memory information of the unreleased memory includes: address information of the memory which is not released, memory size information of the memory which is not released and called when the memory is not released are applied.
The code information causing memory leak in the program includes: address information of an unreleased memory applied by a code causing memory leak in a program, memory size information of the unreleased memory applied by the code causing memory leak in the program, and line number information of the code causing memory leak in the program.
Optionally, in an embodiment of the present application, the apparatus 200 for detecting a memory leak further includes:
and the triggering unit is used for triggering the driving module of the program, so that the driving module reads the test case file and controls the program to execute the operation corresponding to the test case file according to the test case file. The test case file comprises the operation to be executed by the program.
Optionally, in a specific embodiment of the present application, the program is an ultrasonic detection program; wherein, the test case file comprises: fields corresponding to the operational flow in different modes of the ultrasound detection program; the fields in the test case file corresponding to the operation flow in different modes of the ultrasonic detection program can be edited and adjusted.
Optionally, in a specific embodiment of the present application, when the triggering unit executes the driving module that triggers the program, the triggering unit is configured to:
and triggering the drive module of the program by calling the function interface corresponding to the drive module of the program.
Optionally, in an embodiment of the present application, the apparatus 200 for detecting a memory leak further includes: a first receiving unit and a second receiving unit.
And the first receiving unit is used for receiving the starting instruction sent by the driving module. The start instruction is used for controlling the recording unit to start to execute the operation of recording the memory information of the unreleased memory.
And the second receiving unit is used for receiving the ending instruction sent by the driving module. The ending instruction is used for controlling the recording unit to end the operation of recording the memory information of the unreleased memory. And the ending instruction is sent out after the drive module reads the test case file.
Optionally, in an embodiment of the present application, the memory leak detection tool is a linkable library file, and the memory leak detection tool is bound to a device running the program. The device may be an ultrasound device.
The specific principle and the execution process of each unit in the device for detecting memory leakage disclosed in the above embodiment of the present invention are the same as those of the method for detecting memory leakage disclosed in the above embodiment of the present invention, and reference may be made to corresponding parts in the method for detecting memory leakage disclosed in the above embodiment of the present invention, which are not described herein again.
The device 200 for detecting memory leakage provided by the present application is applied to a memory leakage detection tool, wherein the memory leakage detection tool is linked with a program, and in the process of running the program, the recording unit 201 records memory information of an unreleased memory according to the conditions of memory application and memory release. The first generation unit 202 generates a periodic memory leak report according to a preset cycle. Wherein the periodic memory leak report includes the recorded memory information of the unreleased memory. After the program is run, the parsing unit 203 parses out the code information causing the memory leak in the program according to the memory information of the unreleased memory in the generated multiple sets of staged memory leak reports. The codes causing the memory leakage in the program are codes of which the unreleased memory is increased along with the increase of the running times of the codes. The second generation unit 204 then regenerates the final memory leak report. The final memory leak report includes information of the code causing the memory leak in the program. The analyzing unit 203 can analyze the codes of the unreleased memories in the program, which are increased along with the increase of the running times of the codes, according to the memory information of the unreleased memories in the generated multi-part staged memory leak reports, so that the codes causing the memory leak in the program do not need to be analyzed manually, and the efficiency of detecting the memory leak is improved.
Those skilled in the art can make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
It is further noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.

Claims (14)

1. A method for detecting a memory leak is applied to a memory leak detection tool, wherein the memory leak detection tool is linked with a program, and the method for detecting a memory leak includes:
in the process of running the program, recording the memory information of the unreleased memory according to the memory application and release conditions;
generating a periodic memory leak report according to a preset period; wherein the periodic memory leak report includes memory information of unreleased memory recorded by the memory leak detection tool;
after the program is operated, analyzing code information causing memory leakage in the program according to memory information of unreleased memories in the generated multiple periodic memory leakage reports; wherein, the codes causing memory leak in the program are codes which do not release memory and increase along with the increase of the running times of the codes in the multi-share staged memory leak report;
generating a final memory leak report; wherein the final memory leak report includes information of codes causing memory leaks in the program.
2. The method according to claim 1, wherein the memory information of the unreleased memory comprises: address information of the unreleased memory, memory size information of the unreleased memory, and stack address information called when the unreleased memory is applied;
the code information causing the memory leak in the program comprises: address information of an unreleased memory applied by a code causing memory leakage in the program, memory size information of the unreleased memory applied by the code causing memory leakage in the program, and line number information of the code causing memory leakage in the program.
3. The method according to claim 1, wherein before recording the memory information of the unreleased memory according to the memory application and the memory release condition, the method further comprises:
triggering a driving module of the program, enabling the driving module to read a test case file, and controlling the program to execute an operation corresponding to the test case file according to the test case file; and the test case file comprises the operation which needs to be executed by the program.
4. The method of claim 3, wherein the procedure is an ultrasonic testing procedure;
wherein the test case file comprises: fields corresponding to operational flow in different modes of the ultrasound detection program; and fields in the test case file, which correspond to the operation streams in different modes of the ultrasonic detection program, can be edited and adjusted.
5. The method of claim 3, wherein after triggering the driver module of the program, further comprising:
receiving a starting instruction sent by the driving module; the starting instruction is used for controlling the memory leak detection tool to start to execute the operation of recording the memory information of the unreleased memory;
receiving an ending instruction sent by the driving module; the ending instruction is used for controlling the memory leak detection tool to end the operation of recording the memory information of the unreleased memory; and the ending instruction is sent out after the drive module finishes reading the test case file.
6. The method of claim 3, wherein triggering the driver module of the program comprises:
and triggering the drive module of the program by calling a function interface corresponding to the drive module of the program.
7. The method of any of claims 1 to 6, wherein the memory leak detection tool is a linkable library file, the memory leak detection tool being bound to a device running the program.
8. A device for detecting a memory leak, which is applied to a memory leak detection tool, wherein the memory leak detection tool is linked to a program, and the device for detecting a memory leak comprises:
the recording unit is used for recording the memory information of the unreleased memory according to the memory application and release conditions in the program running process;
the first generating unit is used for generating a periodic memory leakage report according to a preset period; wherein, the periodic memory leak report includes the memory information of the unreleased memory recorded by the recording unit;
the analysis unit is used for analyzing code information causing memory leakage in the program according to the memory information of the unreleased memory in the multiple sets of staged memory leakage reports generated by the first generation unit after the program operation is finished; wherein, the codes causing memory leak in the program are codes which do not release memory and increase along with the increase of the running times of the codes in the multi-share staged memory leak report;
the second generating unit is used for generating a final memory leak report; wherein the final memory leak report includes information of codes causing memory leaks in the program.
9. The apparatus of claim 8, wherein the memory information of the unreleased memory comprises: address information of the unreleased memory, memory size information of the unreleased memory, and stack address information called when the unreleased memory is applied;
the code information causing the memory leak in the program comprises: address information of an unreleased memory applied by a code causing memory leakage in the program, memory size information of the unreleased memory applied by the code causing memory leakage in the program, and line number information of the code causing memory leakage in the program.
10. The apparatus of claim 8, further comprising:
the triggering unit is used for triggering the driving module of the program, enabling the driving module to read the test case file and controlling the program to execute the operation corresponding to the test case file according to the test case file; and the test case file comprises the operation which needs to be executed by the program.
11. The apparatus of claim 10, wherein the procedure is an ultrasonic detection procedure;
wherein the test case file comprises: fields corresponding to operational flow in different modes of the ultrasound detection program; and fields in the test case file, which correspond to the operation streams in different modes of the ultrasonic detection program, can be edited and adjusted.
12. The apparatus of claim 10, further comprising:
the first receiving unit is used for receiving a starting instruction sent by the driving module; the starting instruction is used for controlling the recording unit to start to execute the operation of recording the memory information of the unreleased memory;
the second receiving unit is used for receiving an ending instruction sent by the driving module; the ending instruction is used for controlling the recording unit to end the operation of recording the memory information of the unreleased memory; and the ending instruction is sent out after the drive module finishes reading the test case file.
13. The apparatus of claim 10, wherein the triggering unit, when executing the driver module that triggers the program, is configured to:
and triggering the drive module of the program by calling a function interface corresponding to the drive module of the program.
14. The apparatus of any one of claims 8 to 13, wherein the memory leak detection tool is a linkable library file, the memory leak detection tool being bound to a device running the program.
CN201911048075.6A 2019-10-30 2019-10-30 Method and device for detecting memory leakage Pending CN110795355A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911048075.6A CN110795355A (en) 2019-10-30 2019-10-30 Method and device for detecting memory leakage

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911048075.6A CN110795355A (en) 2019-10-30 2019-10-30 Method and device for detecting memory leakage

Publications (1)

Publication Number Publication Date
CN110795355A true CN110795355A (en) 2020-02-14

Family

ID=69442176

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911048075.6A Pending CN110795355A (en) 2019-10-30 2019-10-30 Method and device for detecting memory leakage

Country Status (1)

Country Link
CN (1) CN110795355A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111382076A (en) * 2020-03-10 2020-07-07 北京字节跳动网络技术有限公司 Application program testing method and device, electronic equipment and computer storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050091646A1 (en) * 2003-10-24 2005-04-28 Microsoft Corporation Statistical memory leak detection
WO2010043176A1 (en) * 2008-10-17 2010-04-22 华为技术有限公司 Memory leak detecting method and device
CN102681938A (en) * 2012-05-15 2012-09-19 青岛海信移动通信技术股份有限公司 Memory leakage detecting method and device
CN106933733A (en) * 2015-12-30 2017-07-07 华为技术有限公司 A kind of method and apparatus for determining RAM leakage position
CN107346285A (en) * 2017-05-26 2017-11-14 郑州云海信息技术有限公司 A kind of method for detecting memory leakage and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050091646A1 (en) * 2003-10-24 2005-04-28 Microsoft Corporation Statistical memory leak detection
WO2010043176A1 (en) * 2008-10-17 2010-04-22 华为技术有限公司 Memory leak detecting method and device
CN102681938A (en) * 2012-05-15 2012-09-19 青岛海信移动通信技术股份有限公司 Memory leakage detecting method and device
CN106933733A (en) * 2015-12-30 2017-07-07 华为技术有限公司 A kind of method and apparatus for determining RAM leakage position
CN107346285A (en) * 2017-05-26 2017-11-14 郑州云海信息技术有限公司 A kind of method for detecting memory leakage and device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111382076A (en) * 2020-03-10 2020-07-07 北京字节跳动网络技术有限公司 Application program testing method and device, electronic equipment and computer storage medium
CN111382076B (en) * 2020-03-10 2023-04-25 抖音视界有限公司 Application program testing method and device, electronic equipment and computer storage medium

Similar Documents

Publication Publication Date Title
KR102537875B1 (en) Method and apparatus for dinamically injecting fault for vehicle ecu software test
WO2009108203A1 (en) Identification of elements of currently-executing component script
CN105426310B (en) A kind of method and apparatus for the performance for detecting target process
CN101814217B (en) Method for testing self-service device, device and system
CN111966457B (en) Malicious code detection method and system based on snapshot
CN114860586A (en) Binary multi-executive software instrumentation method based on dynamic instrumentation
CN110795355A (en) Method and device for detecting memory leakage
CN101620563B (en) Method for automatically testing input playback mode of terminal system
CN105630661A (en) Automatic cross-system program debugging method and device
CN103150226A (en) Abnormal dump and recovery system for computer model and dump and recovery method thereof
CN107562621B (en) Method and device for determining incidence relation between manual test case and tested code
JP2009294846A (en) Test case generator, and test case generation program and method
CN115629968A (en) Test data recording method and device
CN109542341B (en) Read-write IO monitoring method, device, terminal and computer readable storage medium
CN114141302A (en) Test method of solid state disk and electronic equipment
CN102519514B (en) One-click automatic testing realization method of electronic test instrument
CN110737573A (en) Method and device for automatically testing user interface UI
US8997048B1 (en) Method and apparatus for profiling a virtual machine
CN108681506B (en) Pressure testing method and device
JP2008135008A (en) Program module verification method
CN116257437A (en) ADAS system defect verification method and device based on real vehicle data reinjection
CN111666200A (en) Testing method and terminal for time consumption of cold start of PC software
CN115268392A (en) Automatic testing method, system and device
CN101556552A (en) Test method of basic input output system
CN113590092A (en) Script generation method and device and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20200214