CN100389403C - Memory leakage detection and prevention method - Google Patents

Memory leakage detection and prevention method Download PDF

Info

Publication number
CN100389403C
CN100389403C CNB2005100632661A CN200510063266A CN100389403C CN 100389403 C CN100389403 C CN 100389403C CN B2005100632661 A CNB2005100632661 A CN B2005100632661A CN 200510063266 A CN200510063266 A CN 200510063266A CN 100389403 C CN100389403 C CN 100389403C
Authority
CN
China
Prior art keywords
memory block
time
memory
time tag
label
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.)
Expired - Fee Related
Application number
CNB2005100632661A
Other languages
Chinese (zh)
Other versions
CN1845080A (en
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.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CNB2005100632661A priority Critical patent/CN100389403C/en
Publication of CN1845080A publication Critical patent/CN1845080A/en
Application granted granted Critical
Publication of CN100389403C publication Critical patent/CN100389403C/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention relates to a memory leakage detection and prevention method comprising a setting step, an assignment step, a detection step and a judgment step, wherein in the setting step, time labels for recording the occupation time of memory blocks are added in an operation system; in the assignment step, when the memory blocks are distributed by a memory management module, the time labels are assigned to record system time in memory block distribution; when the memory blocks are visited, value of the time labels are updated to current system time; in the detection step, the time labels in the memory blocks are detected; in the judgment step, the present invention judges whether time occupied by the internal blocks is longer than the forced release time according to time recorded by the time labels; if the time is longer than the forced release time, the memory blocks have leakage; if the time is not longer than the forced release time, the memory blocks do not have leakage. The present invention can judge whether the memory blocks are released according to a detection result, or the memory blocks can be directly released when the leakage is detected. Thus, the present invention with convenient detection effectively prevents memory leakage.

Description

The method of Memory leakage detection and recovery
Technical field
The present invention relates to the memory management of computer system, especially refer to the method for a kind of Memory leakage detection and recovery.
Background technology
Internal memory is the essential resource of running software, and the memory source deficiency will cause running software unusual, and system can't provide normal function even withdraw from service.Especially in the software architecture that message-oriented is handled, all communicate between each process, need be used for the buffer memory of message content, and send this memory block of back release in message for every suitable memory block of distribution of messages by message.In the long playing process of software, may not discharge owing to the internal memory that a variety of causes causes distributing, thereby produce memory overflow, cumulative effect may cause the Installed System Memory total amount to reduce so that the phenomenon that exhausts.In this case, system generally can not recover voluntarily, may cause vicious circle when serious, and system withdraws from service.
Be directed to memory overflow, solution of the prior art, for example at first determine the memory block of application program, and the occupied time of different memory blocks of being applied for, when application program is moved, write down the information of its application memory block and releasing memory piece, determine to surpass the memory block that holding time does not discharge as yet at last, determine that by said method it is 02121418 Chinese patent application that the internal memory leak point of application program, particular content see also application number.
The essence of above-mentioned prior art scheme is by adopting the detection module that increases to determine the leakage of memory block, but has following defective: only can detect the memory overflow situation that takes place behind the detection module software startup, can't detect for the memory overflow before the detection module software startup; The measure of leaking of preventing is not provided.
Summary of the invention
The problem that the present invention solves provides the method that a kind of memory overflow detects, and effectively detects memory overflow.
Another problem that the present invention solves provides the method that a kind of memory overflow recovers, and effectively detects memory overflow and also can directly recover behind the discovery memory overflow.
Correspondingly, the method for Memory leakage detection of the present invention comprises: setting steps, in operating system, increase for the record memory block time tag of occupied time, and arrange whether the expression memory block is the overall label of global memory block; Whether effectively expression memory block validity label is set; The assignment step, during memory management module storage allocation piece, to the time tag assignment, the system time when distributing this memory block with record, and when memory block is accessed, the value of time tag is updated to the current system time; Detecting step according to the value of validity label, judges whether this memory block is effective; If this memory block is invalid, then do not detect the time tag of this memory block; If this memory block is effective, then according to the value of overall label, judge whether this memory block is global memory block, if global memory block, then do not detect the time tag of this memory block; If not global memory block, then carry out determining step; Determining step according to time tag writing time, judges that memory block takies duration and whether surpasses and force release time, if surpass then memory block leaks, if do not surpass, then leaks.
The method that memory overflow of the present invention recovers comprises: setting steps, in operating system, increase for the record memory block time tag of occupied time, and arrange whether the sign memory block is the overall label of global memory block; Whether effectively expression memory block validity label is set; The assignment step, during memory management module storage allocation piece, to the time tag assignment, the system time when distributing this memory block with record, and when memory block is accessed, the value of time tag is updated to the current system time; Detecting step according to the value of validity label, judges whether this memory block is effective; If this memory block is invalid, then do not detect the time tag of this memory block; If this memory block is effective, then according to the value of overall label, judge whether this memory block is global memory block, if global memory block, then do not detect the time tag of this memory block; If not global memory block, then carry out execution in step; Execution in step according to time tag writing time, takies duration at memory block and surpasses when forcing release time, discharges this memory block.
Step is set also comprises the setting of time tag Attribute domain, described time tag Attribute domain is used for the attribute of express time label, further comprises: whether effectively whether expression memory block validity label be the overall label of global memory block with the expression memory block.Realize by the data structure of the attribute information of extended memory block in time tag and time tag attributes territory.
Detecting step and execution in step (detecting step and determining step) comprise the steps: the value according to the validity label, judge whether this memory block is effective; If this memory block is invalid, then do not detect the time tag of this memory block; If this memory block is effective, then according to the value of overall label, judge whether this memory block is global memory block, if global memory block, then do not detect the time tag of this memory block; If not global memory block, then carry out detecting step.
Carry out detecting step and execution in step (detecting step and determining step) by sense cycle.Described sense cycle realizes by the cycle timer that startup is arranged in the memory management module.
Described pressure takies maximum duration according to memory block and estimate setting release time.
The present invention compared with prior art, the present invention has the following advantages:
By memory block being increased time tag and according to time tag the memory block that has distributed being safeguarded, detected and judges, Memory leakage detection makes things convenient for and recovers when memory overflow;
Prevent the flase drop survey by validity label and overall label, get rid of unnecessary detection;
Internal memory detects and safeguards and can manually start and close, and the cycle of detection can be used as systematic parameter and dynamically adjusts.
Description of drawings
Fig. 1 is the process flow diagram of the method for memory overflow detection of the present invention.
Fig. 2 is the process flow diagram of the method for memory overflow recovery of the present invention.
Embodiment
The method of Memory leakage detection of the present invention and recovery can detect memory block and leak, and the record testing result judges whether the releasing memory piece according to testing result again to make things convenient for positioning problems and inspection; Perhaps when finding that memory block leaks, directly discharge recovery, prevent system deterioration, the long playing stability of raising system.
Message in the system all is effective property, and the message that does not obtain handling above certain hour is invalid, and the memory block of its distribution also just is judged as leakage, can be released.
Please refer to Fig. 1, according to described principle, the method that memory overflow of the present invention detects comprises:
Setting steps in operating system, increases for the record memory block time tag of occupied time;
The assignment step, during memory management module storage allocation piece, to the time tag assignment, the system time when distributing this memory block with record, and when memory block is visited, the value of time tag is updated to current system time;
Detecting step, the time tag of detection memory block;
Determining step according to time tag writing time, judges that memory block takies duration and whether surpasses and force release time, if surpass then memory block leaks, if do not surpass, then leaks.
The record testing result judges whether the releasing memory piece according to testing result again to make things convenient for positioning problems and inspection, if need to discharge, then can be idle realization by operating system API (API) or the state of directly revising memory block.
In like manner, please refer to shown in Figure 2ly, the method that memory overflow of the present invention recovers comprises:
Setting steps in operating system, increases for the record memory block time tag of occupied time;
The assignment step, during memory management module storage allocation piece, to the time tag assignment, the system time when distributing this memory block with record, and when memory block is visited, the value of time tag is updated to current system time;
Detecting step, the time tag of detection memory block;
Execution in step according to time tag writing time, takies duration (being the time interval of current time and last visit time) at memory block, surpasses when forcing release time, discharges this memory block (can discharge by the interface of invoke memory administration module).
Described pressure takies maximum duration according to memory block and estimate setting release time.
In the described assignment step, memory block is when needed to the memory management module application of operating system by application module, memory management module response application and storage allocation piece, after the memory block application success, application module just can the memory block of this distribution be conducted interviews (read/write) operation, when read-write operation, the time tag of the interface updating memory piece that application module needs while invoke memory administration module provides is the current system time.Real time operating system itself has a time system, and the time of the time of record with operating system is that benchmark calculates.
Also increase the setup times tag attributes in operating system, be used for the attribute of expression time tag, further comprise: effectively whether the expression memory block validity label and the expression memory block overall label of global memory block whether.In operating system, each memory block all has a data structure to preserve the attribute information of this memory block, as: start address, memory block size etc., time tag and time tag Attribute domain are realized by the data structure of the attribute information of extended memory block, promptly increasing time tag and time tag Attribute domain is exactly to increase by two elements in this data structure, identifies the holding time of this memory block.Validity label and overall label all are an attribute of memory block with the time label.
The validity label is exactly an identifier, and for example value is: be that (this memory block of no sign is not valid memory, does not need to detect and judge time tag when memory management module scans (1) or no (0); Be the sign this memory block be valid memory, when memory management module scans, need to detect and judge time tag, if time tag too always to force to discharge this internal memory).It is invalid that the time tag attribute of the memory block that (perhaps detects the memory block leakage) after discharging is set to, and for example can be set to maximal value, full F.
Overall situation labels class is like the validity label, and whether overall, for example value if identifying this memory block: be that (1) or no (0) (is that this memory block of sign is global memory block, does not need to detect and judge time tag when memory management module scans; This memory block of no sign is not global memory block, need to detect and judge time tag when memory management module scans, if time tag too always to force to discharge this internal memory).
Also comprise the steps: the value according to the validity label between described detecting step and the execution in step (detecting step and determining step), judge whether this memory block is effective; If this memory block is invalid, then do not detect the time tag of this memory block; If this memory block is effective, then according to the value of overall label, judge whether this memory block is global memory block; If global memory block, then do not detect the time tag (because global memory block refers to exist always, can d/d memory block, so do not need to detect) of this memory block in system's running; If not global memory block, then carry out detecting step.
Described detecting step and execution in step (detecting step and determining step) are carried out by sense cycle.Described sense cycle realizes by the cycle timer that startup is arranged in the memory management module.Sense cycle is adjustable, for example: find that in transferring survey the current cycle is too short or oversize, can adjust by this function, otherwise remodify code possibly that program compiler can improve the efficient of debugging test like this; And for different application systems, may need different sense cycle, can set sense cycle flexibly at different systems like this.Realize: general application system all has a debugging test interface, can send order to system by this interface, and the adjustment sense cycle can be utilized this interface to come to send an order to system and realize.Detection also can manually start and close, and sense cycle can be used as the systematic parameter adjustment.
The present invention passes through the management to memory block in operational process, the memory overflow of providing convenience detects, effectively prevent memory overflow, can correct automatically, this does not need manual intervention, can reduce the probability of system crash, improve the reliability of system, after memory overflow takes place, recover automatically.

Claims (9)

1. the method that memory overflow detects is characterized in that, comprising:
Setting steps in operating system, increases for the record memory block time tag of occupied time, arranges whether the expression memory block is the overall label of global memory block; Whether effectively expression memory block validity label is set;
The assignment step, during memory management module storage allocation piece, to the time tag assignment, the system time when distributing this memory block with record, and when memory block is visited, the value of time tag is updated to current system time;
Detecting step according to the value of validity label, judges whether this memory block is effective; If this memory block is invalid, then do not detect the time tag of this memory block; If this memory block is effective, then according to the value of overall label, judge whether this memory block is global memory block, if global memory block, then do not detect the time tag of this memory block; If not global memory block, then carry out determining step;
Determining step according to time tag writing time, judges that memory block takies duration and whether surpasses and force release time, if surpass then memory block leaks, if do not surpass, then leaks.
2. the method that memory overflow as claimed in claim 1 detects is characterized in that, described time tag, overall label and validity label are realized by the data structure of the attribute information of extended memory block.
3. the method that detects as each described memory overflow of claim 1 to 2 is characterized in that, forces release time and take maximum duration according to memory block to estimate setting.
4. such as the method for each described Memory leakage detection of claim 1 to 2, it is characterized in that, carry out detecting step and determining step by sense cycle.
5. the method that memory overflow recovers is characterized in that, comprising:
Setting steps in operating system, increases for the record memory block time tag of occupied time, arranges whether the sign memory block is the overall label of global memory block; Whether effectively expression memory block validity label is set;
The assignment step, during memory management module storage allocation piece, to the time tag assignment, the system time when distributing this memory block with record, and when memory block is visited, the value of time tag is updated to current system time;
Detecting step according to the value of validity label, judges whether this memory block is effective; If this memory block is invalid, then do not detect the time tag of this memory block; If this memory block is effective, then according to the value of overall label, judge whether this memory block is global memory block, if global memory block, then do not detect the time tag of this memory block; If not global memory block, then carry out execution in step;
Execution in step according to time tag writing time, takies duration at memory block and surpasses when forcing release time, discharges this memory block.
6. the method that memory overflow as claimed in claim 5 recovers is characterized in that, described time tag, overall label and validity label are realized by the data structure of the attribute information of extended memory block.
7. the method for recovering such as each described memory overflow of claim 5 to 6 is characterized in that, carries out detecting step and execution in step by sense cycle.
8. the method that memory overflow as claimed in claim 7 recovers is characterized in that, described sense cycle realizes by the cycle timer that startup is arranged in the memory management module.
9. the method for recovering as each described memory overflow of claim 5 to 6 is characterized in that, forces release time and take maximum duration according to memory block to estimate setting.
CNB2005100632661A 2005-04-07 2005-04-07 Memory leakage detection and prevention method Expired - Fee Related CN100389403C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2005100632661A CN100389403C (en) 2005-04-07 2005-04-07 Memory leakage detection and prevention method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2005100632661A CN100389403C (en) 2005-04-07 2005-04-07 Memory leakage detection and prevention method

Publications (2)

Publication Number Publication Date
CN1845080A CN1845080A (en) 2006-10-11
CN100389403C true CN100389403C (en) 2008-05-21

Family

ID=37064008

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2005100632661A Expired - Fee Related CN100389403C (en) 2005-04-07 2005-04-07 Memory leakage detection and prevention method

Country Status (1)

Country Link
CN (1) CN100389403C (en)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100504811C (en) * 2007-06-13 2009-06-24 中兴通讯股份有限公司 Method for detecting RAM leakage
CN101615143B (en) * 2008-06-27 2013-04-17 国际商业机器公司 Method and device for diagnosing memory leak
CN101539976B (en) * 2009-04-23 2011-08-31 南京大学 Real-time detection system of binary program memory decay attack
CN103607480B (en) * 2013-11-14 2017-02-08 华为技术有限公司 Method and apparatus for memory resource management, and single board
CN103716234B (en) * 2013-12-19 2017-11-28 汉柏科技有限公司 A kind of method for positioning message memory leak
CN104572460A (en) * 2014-12-30 2015-04-29 大唐移动通信设备有限公司 Memory leak detecting method and memory leak detecting device
CN104731661B (en) * 2015-03-02 2018-12-14 大唐移动通信设备有限公司 A kind of method and device of the program operation resource of recycling leakage
CN105260313B (en) * 2015-10-27 2019-07-05 上海斐讯数据通信技术有限公司 Memory overflow checks system and method
CN106909457A (en) * 2015-12-23 2017-06-30 北京奇虎科技有限公司 EMS memory management process and device
CN109144872A (en) * 2018-08-20 2019-01-04 杭州迪普科技股份有限公司 Detection method, device, terminal device and the readable storage medium storing program for executing of memory overflow

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5842019A (en) * 1996-09-13 1998-11-24 Parasoft Corporation Method and system for dynamically detecting leaked memory space in a computer program
US5953530A (en) * 1995-02-07 1999-09-14 Sun Microsystems, Inc. Method and apparatus for run-time memory access checking and memory leak detection of a multi-threaded program
JP2000293400A (en) * 1999-04-08 2000-10-20 Nec Corp System and method for detecting memory leak and recording medium
CN1466057A (en) * 2002-06-20 2004-01-07 华为技术有限公司 Method for checking sofeware memory leak
CN1538300A (en) * 2003-09-23 2004-10-20 中兴通讯股份有限公司 Method of detecting and location of leakage of internal storage of real-time system localization
CN1604050A (en) * 2003-09-30 2005-04-06 国际商业机器公司 System and method for autonomic memory leak detection and remediation

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5953530A (en) * 1995-02-07 1999-09-14 Sun Microsystems, Inc. Method and apparatus for run-time memory access checking and memory leak detection of a multi-threaded program
US5842019A (en) * 1996-09-13 1998-11-24 Parasoft Corporation Method and system for dynamically detecting leaked memory space in a computer program
JP2000293400A (en) * 1999-04-08 2000-10-20 Nec Corp System and method for detecting memory leak and recording medium
CN1466057A (en) * 2002-06-20 2004-01-07 华为技术有限公司 Method for checking sofeware memory leak
CN1538300A (en) * 2003-09-23 2004-10-20 中兴通讯股份有限公司 Method of detecting and location of leakage of internal storage of real-time system localization
CN1604050A (en) * 2003-09-30 2005-04-06 国际商业机器公司 System and method for autonomic memory leak detection and remediation

Also Published As

Publication number Publication date
CN1845080A (en) 2006-10-11

Similar Documents

Publication Publication Date Title
CN100389403C (en) Memory leakage detection and prevention method
CN100487658C (en) Method for detecting memory accessing outside
CN101369247B (en) Method for creating a memory defect map and optimizing performance using the memory defect map
US20030110426A1 (en) Apparatus and method for error logging on a memory module
CN101369246B (en) System and method for using a memory mapping function to map memory defects
CN1248114C (en) Method for checking sofeware memory leak
CN101414272B (en) Method and apparatus for detecting memory leakage
CN101763305B (en) Method for detecting memory leak of embedded system
US6523141B1 (en) Method and apparatus for post-mortem kernel memory leak detection
CN100392606C (en) Method for leaking memory of positioning virtual operation system
CN101539870A (en) Device and method for detecting memory leak
CN107783908B (en) Linux kernel memory leakage detection method
CN101593152A (en) A kind of portable terminal memory leakage detecting method and device
CN101515242B (en) Method and system for searching and rewriting the task of internal memory
CN105988921A (en) Method and device for detecting out of range problem of memory
CN101551772A (en) Method and apparatus for recording abnormal information of embedded communications equipment
CN109739756B (en) Method and equipment for testing application of mobile terminal
CN100388233C (en) Simple method for deciding embedded system internal storage disclose of no-operation system
CN103164290B (en) application memory management method and device
CN100461120C (en) Method for managing field data-protection memory
CN100487669C (en) Locating method and system for repeated memory release
CN101201778A (en) Method for testing hard disk with expandable firmware interface
JP2005196680A (en) Computer system
CN103390429B (en) The online test method of a kind of hard disk and server
CN102981919B (en) Memory management method of quickly positioning sources of errors

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C17 Cessation of patent right
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20080521

Termination date: 20130407