473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

About memory leak detection.

Hi, all
I really interested in how to check the memory leak of a program.
Your smart guys, do you have excellent ideas that could share with me?
Thank you.

The following is my idea:

In C programming language, there's a "malloc", there must a "free",
my solution of the detection of leak is, find the corresponding "free"
of "malloc". This the first condition.

Another one is much more difficult, the lost of a pointer. I think,
once a pointer is defined, it should be registered. Any operations on
pointer, like assigned or "free", all the operation must be recorded!
So, we can find the lost of pointer and return to programmers.

This is code-based detection.

Application-based detection needs asm knowledge, I will try it then.

Need your comments and advice. Thank you!
Nov 14 '05 #1
7 2623
mosaic <mo****@hotmail.com> wrote:
In C programming language, there's a "malloc", there must a "free",
my solution of the detection of leak is, find the corresponding "free"
of "malloc". This the first condition.


This is also impossible to do outside the running program. No other
instance can possibly determine with any reliability which individual
malloc()ed block a given call of free() will actually act upon.

--
Hans-Bernhard Broeker (br*****@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Nov 14 '05 #2
In 'comp.lang.c', mosaic <mo****@hotmail.com> wrote:
Hi, all
I really interested in how to check the memory leak of a program.
Your smart guys, do you have excellent ideas that could share with me?
Thank you.

The following is my idea:

In C programming language, there's a "malloc", there must a "free",
Real-life is not that simple. It may have calloc(), and more tricky(),
realloc() !
my solution of the detection of leak is, find the corresponding "free"
of "malloc". This the first condition.

Another one is much more difficult, the lost of a pointer. I think,
once a pointer is defined, it should be registered. Any operations on
pointer, like assigned or "free", all the operation must be recorded!
So, we can find the lost of pointer and return to programmers.

This is code-based detection.

Application-based detection needs asm knowledge, I will try it then.


FYI (drop me an email if you are stuck):

http://mapage.noos.fr/emdel/sysalloc_um.htm
http://mapage.noos.fr/emdel/clib/ed/inc/SYSALLOC.H
http://mapage.noos.fr/emdel/clib/ed/src/SYSALLOC.C

Missing stuffs at:
http://mapage.noos.fr/emdel/clib.htm

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #3
In <cd**********@mail.cn99.com> mosaic <mo****@hotmail.com> writes:
I really interested in how to check the memory leak of a program.


For starters, use one of the many debugging malloc implementations
available that also includes memory leak detection. Choose one coming
with source code, so that you can see how it is done. See the FAQ or
google yourself.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #4
On Thu, 15 Jul 2004 20:37:26 +0800, mosaic wrote:
Hi, all
I really interested in how to check the memory leak of a program.
Your smart guys, do you have excellent ideas that could share with me?
Thank you.

The following is my idea:

In C programming language, there's a "malloc", there must a "free",
my solution of the detection of leak is, find the corresponding "free"
of "malloc". This the first condition.

Another one is much more difficult, the lost of a pointer. I think,
once a pointer is defined, it should be registered. Any operations on
pointer, like assigned or "free", all the operation must be recorded!
So, we can find the lost of pointer and return to programmers.

This is code-based detection.

Application-based detection needs asm knowledge, I will try it then.

Need your comments and advice. Thank you!

The "Standford Checker" already has a lot going when it comes to C source
code analyzis, there are probably some interresting papers.
http://metacomp.stanford.edu/

(or for something similar; http://smatch.sourceforge.net/)
Nov 14 '05 #5
mosaic wrote:
Hi, all
I really interested in how to check the memory leak of a program.
Your smart guys, do you have excellent ideas that could share with me?
Thank you.

The following is my idea:

In C programming language, there's a "malloc", there must a "free",
my solution of the detection of leak is, find the corresponding "free"
of "malloc". This the first condition.

Another one is much more difficult, the lost of a pointer. I think,
once a pointer is defined, it should be registered. Any operations on
pointer, like assigned or "free", all the operation must be recorded!
So, we can find the lost of pointer and return to programmers.

This is code-based detection.

Application-based detection needs asm knowledge, I will try it then.


Well - the whole idea of memory detection is tied closely to the
implementation. For eg, one memory leak detector that i could think is
the mtrace utility .
http://www.gnu.org/software/libc/man...on%20Debugging.

This one is really good, but as i said before, works only where you
have glibc implementation .

HTH .

--
Karthik.
Nov 14 '05 #6
Nils O. Selåsdal 写道:
On Thu, 15 Jul 2004 20:37:26 +0800, mosaic wrote:

Hi, all
I really interested in how to check the memory leak of a program.
Your smart guys, do you have excellent ideas that could share with me?
Thank you.

The following is my idea:

In C programming language, there's a "malloc", there must a "free",
my solution of the detection of leak is, find the corresponding "free"
of "malloc". This the first condition.

Another one is much more difficult, the lost of a pointer. I think,
once a pointer is defined, it should be registered. Any operations on
pointer, like assigned or "free", all the operation must be recorded!
So, we can find the lost of pointer and return to programmers.

This is code-based detection.

Application-based detection needs asm knowledge, I will try it then.

Need your comments and advice. Thank you!


The "Standford Checker" already has a lot going when it comes to C source
code analyzis, there are probably some interresting papers.
http://metacomp.stanford.edu/

(or for something similar; http://smatch.sourceforge.net/)


Thank you very much for your kind suggestiones. I will try to hack the
papers and work on my own code.
And, thank you all.
Nov 14 '05 #7
mosaic wrote:
Hi, all
I really interested in how to check the memory leak of a program.
Your smart guys, do you have excellent ideas that could share with me?
Thank you.

The following is my idea:

In C programming language, there's a "malloc", there must a "free",
my solution of the detection of leak is, find the corresponding "free"
of "malloc". This the first condition.

Another one is much more difficult, the lost of a pointer. I think,
once a pointer is defined, it should be registered. Any operations on
pointer, like assigned or "free", all the operation must be recorded!
So, we can find the lost of pointer and return to programmers.

This is code-based detection.

Application-based detection needs asm knowledge, I will try it then.

Need your comments and advice. Thank you!


There exist a lot of Tools doing the job for you, but unfortunatly they
are not for free (BoundsChecker is a very good one, I work with, but it
is expensive ~1000 €?).

If you work with Dev C++ from MS they have a lot of Debugging-Macros,
which are very usefull. Search for 'memory leaks' and you will get a lot
of useful hints.

best regards
Bernhard
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: __jakal__ | last post by:
Hello, Is there any good memory leak detection software for C++ available as a freeware... I had used purify but had to discontinue due to huge license fees... Also tried Sun workshop memory...
6
by: Scott Niu | last post by:
Hi, I have this following simple c++ program, it will produce memory leak ( see what I did below ). My observation also showed that: There will be a mem leak when all the 3 conditions are true:...
0
by: Frank Lopez | last post by:
Does anyone know if Microsoft generated a whitepaper on this topic? Does anyone know what the solution is? (meaning, eliminate the leak problem -- I am seeing three memory leaks from...
3
by: roberts.noah | last post by:
Yesturday I chased down a memory leak being reported by our leak detection library. It lead me to question this line of code: str_instance = std::string(); I changed it to...
4
by: mast2as | last post by:
Hi again I was still debugging some code and check for memory leaks with valgrind and found out that valgrind finds a leak when i use deque<Somethingaqueue ?! I am compiling under Linux for...
8
by: kk_oop | last post by:
Hi. Any recommendations for memory leak detection tools for C++ running on Linux or Solaris? I'm interested in static (compile time) and runtime detection. It's for a large project. Thanks! ...
1
by: dh | last post by:
Will GC.GetTotalMemory(true) reliably tell if a console app could have a memory leak, given the nature of memory management of GC in .NET? Like calling it two times, each at the beginning and right...
1
by: Archana | last post by:
Hi all, I am new to c++. I have written one c++ application. I want to detect memory leaks from my program. I tried with following code which i got from net. if(_CrtDumpMemoryLeaks() ==...
16
by: graham.keellings | last post by:
hi, I'm looking for an open source memory pool. It's for use on an embedded system, if that makes any difference. Something with garbage collection/defragmentation would be nice. It should have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.