CN1845080A - Memory leakage detection and prevention method - Google Patents

Memory leakage detection and prevention method Download PDF

Info

Publication number
CN1845080A
CN1845080A CN 200510063266 CN200510063266A CN1845080A CN 1845080 A CN1845080 A CN 1845080A CN 200510063266 CN200510063266 CN 200510063266 CN 200510063266 A CN200510063266 A CN 200510063266A CN 1845080 A CN1845080 A CN 1845080A
Authority
CN
China
Prior art keywords
memory block
time
memory
time tag
overflow
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.)
Granted
Application number
CN 200510063266
Other languages
Chinese (zh)
Other versions
CN100389403C (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 method for detecting and avoiding memory leakage, which comprises: setting step that increasing a time label in the operation system to record the time that memory is occupied; evaluating step that memory manage module evaluates the time label when distributing memory blocks to record the system time that distributing said memory block and refreshing the value of time label into present system time when accessing the memory block; checking step that checking the time label of memory block; judging step that judging if the memory block occupy time is longer than the forced release time according to the time recorded in time label, and if it is longer, the memory block is leaked, or else, the memory block is not leaked. The invention can effectively judge if the memory block should be released, and directly release memory block when the leakage is detected.

Description

The method that memory overflow detects and prevents
Technical field
The present invention relates to the memory management of computer system, refer to the method that a kind of memory overflow detects and prevents especially.
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 cycle 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 prevents, effectively detects memory overflow and also can directly recover behind the discovery memory overflow.
Correspondingly, the method that memory overflow of the present invention detects comprises: step is set, and in operating system, increase is used to write down the 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; Detect step, detect the time tag of 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 method that memory overflow of the present invention prevents comprises: step is set, and in operating system, increase is used to write down the 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; Detect step, detect the time tag of memory block; 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.
It is invalid that execution in step comprises that also the validity label of the memory block after discharging is set to.
Detect step and execution in step (detecting step and determining step) and comprise the steps: value, judge whether this memory block is effective according to the validity label; 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 and detect step.
Carry out detection 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 is safeguarded, detected and judges, memory overflow is easy to detect and effectively prevent 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 that prevents of memory overflow of the present invention.
Embodiment
Memory overflow detection of the present invention and the method that prevents 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:
Step is set, and in operating system, increase is used to write down the 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;
Detect step, detect the time tag of 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, discharges if desired, then can be idle realization by operating system API (application programming interface) 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 prevents comprises:
Step is set, and in operating system, increase is used to write down the 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;
Detect step, detect the time tag of 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 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 in operating system the time tag attribute is set, be used for the attribute of express time label, 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 (1) or (0) (not identifying this memory block is not valid memory, does not need detection and judgement time label when memory management module scan; Be the sign this memory block be valid memory, when memory management module scans, need detect and the judgement time label, 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, identifies this memory block whether overall situation, for example value: be (1) or not (0) (be that this memory block of sign is a global memory block, when memory management module scan, do not need detection and judgement time label; Not identifying this memory block is not global memory block, when memory management module scans, need detect and the judgement time label, if time tag too always to force to discharge this internal memory).
Also comprise the steps: value between described detection step and the execution in step (detecting step and determining step), judge whether this memory block is effective according to the validity label; If this memory block is invalid, then do not detect the time tag of this memory block; If this memory block is effective,, judge whether this memory block is global memory block then according to the value of overall label; If global memory block, then do not detect the time tag (always exist, can d/d memory block, so do not need to detect) of this memory block because global memory block is meant in system's operational process; If not global memory block, then carry out and detect step.
Described detection 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 (14)

1. the method that memory overflow detects is characterized in that, comprising:
Step is set, and in operating system, increase is used to write down the 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;
Detect step, detect the time tag of 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.
2. the method that memory overflow as claimed in claim 1 detects, it is characterized in that, 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.
3. the method that memory overflow as claimed in claim 2 detects is characterized in that, realize by the data structure of the attribute information of extended memory block in time tag and time tag attributes territory.
4. the method that memory overflow as claimed in claim 2 detects is characterized in that, detects between step and the determining step also to comprise:
According to the value of 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 and detect step.
5. the method that detects as each described memory overflow of claim 1 to 4 is characterized in that, forces release time and take maximum duration according to memory block to estimate setting.
6. the method that detects as each described memory overflow of claim 1 to 4 is characterized in that, carries out by sense cycle and detects step and determining step.
7. the method that memory overflow prevents is characterized in that, comprising:
Step is set, and in operating system, increase is used to write down the 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;
Detect step, detect the time tag of memory block;
Execution in step according to time tag writing time, takies duration at memory block and surpasses when forcing release time, discharges this memory block.
8. the method that memory overflow as claimed in claim 7 prevents, it is characterized in that, 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.
9. the method that memory overflow as claimed in claim 8 prevents is characterized in that, realize by the data structure of the attribute information of extended memory block in time tag and time tag attributes territory.
10. the method that memory overflow as claimed in claim 8 prevents is characterized in that, it is invalid that execution in step comprises that also the validity label of the memory block after discharging is set to.
11. the method that memory overflow as claimed in claim 10 prevents is characterized in that, detects the value that also comprises the steps: between step and the execution in step according to the 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 and detect step.
12. the method as each described memory overflow of claim 7 to 11 prevents is characterized in that, carries out by sense cycle and detects step and execution in step.
13. the method that memory overflow as claimed in claim 12 prevents is characterized in that, described sense cycle realizes by the cycle timer that startup is arranged in the memory management module.
14. the method as each described memory overflow of claim 7 to 11 prevents is characterized in that, forces take maximum duration according to memory block release time and estimates 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 true CN1845080A (en) 2006-10-11
CN100389403C 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)

Cited By (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
CN101539976B (en) * 2009-04-23 2011-08-31 南京大学 Real-time detection system of binary program memory decay attack
CN101615143B (en) * 2008-06-27 2013-04-17 国际商业机器公司 Method and device for diagnosing memory leak
CN103607480A (en) * 2013-11-14 2014-02-26 华为技术有限公司 Method and apparatus for memory resource management, and single board
CN103716234A (en) * 2013-12-19 2014-04-09 汉柏科技有限公司 Message memory leak locating method
CN104572460A (en) * 2014-12-30 2015-04-29 大唐移动通信设备有限公司 Memory leak detecting method and memory leak detecting device
CN104731661A (en) * 2015-03-02 2015-06-24 大唐移动通信设备有限公司 Method and device for recycling revealed program running resources
CN105260313A (en) * 2015-10-27 2016-01-20 上海斐讯数据通信技术有限公司 Memory leak checking 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

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0729097A1 (en) * 1995-02-07 1996-08-28 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
JP3735484B2 (en) * 1999-04-08 2006-01-18 日本電気株式会社 Memory leak detection system, memory leak detection method, and recording medium
CN1248114C (en) * 2002-06-20 2006-03-29 华为技术有限公司 Method for checking sofeware memory leak
CN1327352C (en) * 2003-09-23 2007-07-18 中兴通讯股份有限公司 Method of detecting and location of leakage of internal storage of real-time system localization
US20050081190A1 (en) * 2003-09-30 2005-04-14 International Business Machines Corporation Autonomic memory leak detection and remediation

Cited By (14)

* 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
CN103607480A (en) * 2013-11-14 2014-02-26 华为技术有限公司 Method and apparatus for memory resource management, and single board
CN103716234A (en) * 2013-12-19 2014-04-09 汉柏科技有限公司 Message memory leak locating method
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
CN104731661A (en) * 2015-03-02 2015-06-24 大唐移动通信设备有限公司 Method and device for recycling revealed program running resources
CN104731661B (en) * 2015-03-02 2018-12-14 大唐移动通信设备有限公司 A kind of method and device of the program operation resource of recycling leakage
CN105260313A (en) * 2015-10-27 2016-01-20 上海斐讯数据通信技术有限公司 Memory leak checking system and method
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

Also Published As

Publication number Publication date
CN100389403C (en) 2008-05-21

Similar Documents

Publication Publication Date Title
CN1845080A (en) Memory leakage detection and prevention method
CN1248114C (en) Method for checking sofeware memory leak
US6976197B2 (en) Apparatus and method for error logging on a memory module
US20100205230A1 (en) Method and System for Inspecting Memory Leaks and Analyzing Contents of Garbage Collection Files
US7845006B2 (en) Mitigating malicious exploitation of a vulnerability in a software application by selectively trapping execution along a code path
US7765528B2 (en) Identifying sources of memory retention
US7293263B2 (en) System and method for memory leak detection in a virtual machine environment
CN100487658C (en) Method for detecting memory accessing outside
US20070255775A1 (en) Method and system for inspecting memory leaks
CN100504807C (en) EMS memory leakage testing method in communication apparatus system
CN100440163C (en) Method and system for analysis processing of computer program
US20080243969A1 (en) Method and system for customizing allocation statistics
US8793289B2 (en) Method and system for detecting memory leaks and copying garbage collection files
US7761852B2 (en) Fast detection of the origins of memory leaks when using pooled resources
CN112148221B (en) Method, device, equipment and storage medium for inspecting redundant array of inexpensive disks
WO2010043176A1 (en) Memory leak detecting method and device
CN100392606C (en) Method for leaking memory of positioning virtual operation system
CN107133144B (en) Memory monitoring device and method for dynamically monitoring use errors of heap memory
CN101515242B (en) Method and system for searching and rewriting the task of internal memory
US7096339B2 (en) System and method for detecting memory management programming errors
US7565645B2 (en) Method and apparatus for marking code for data versioning
CN105988921A (en) Method and device for detecting out of range problem of memory
US20110113183A1 (en) Method for Managing a Non-Violate Memory and Computer Readable Medium Thereof
US7725771B2 (en) Method and system for providing enhanced memory error messages
US6513133B1 (en) Uniformly distributed induction of exceptions for testing computer software

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