Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

for memory leaks

1 view
Skip to first unread message

blackbiscuit

unread,
Nov 27, 2009, 8:36:34 AM11/27/09
to
Dear all,

In MSVC, there is some function called _CrtDumpMemoryLeaks which helps
us to find the memory leak point in the source code. But may I ask if
I were programming on Linux platform or Mac OS X, is there any similar
way to detect the memory leak in the C++ source code? Is there any
such like functions in the standard library?

Thanks for your attention.

Best wishes,
Tony

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

alapaa

unread,
Nov 28, 2009, 3:37:33 AM11/28/09
to
On Nov 27, 2:36 pm, blackbiscuit <infozyzh...@gmail.com> wrote:
> Dear all,
>
> In MSVC, there is some function called _CrtDumpMemoryLeaks which helps
> us to find the memory leak point in the source code. But may I ask if
> I were programming on Linux platform or Mac OS X, is there any similar
> way to detect the memory leak in the C++ source code? Is there any
> such like functions in the standard library?
>

For Linux, Valgrind is great! But the last time I used it, it did only
heap checks, not stack. There are commercial tools such as Rational
Purify that can check both heap and stack, but Valgrind is free and it
is a really useful tool. I know it works well for C, but I am not sure
if it is as useful for C++.

/Erik Alap��

Ulrich Eckhardt

unread,
Nov 28, 2009, 3:40:58 AM11/28/09
to
blackbiscuit wrote:
> In MSVC, there is some function called _CrtDumpMemoryLeaks which helps
> us to find the memory leak point in the source code. But may I ask if
> I were programming on Linux platform or Mac OS X, is there any similar
> way to detect the memory leak in the C++ source code?

This is called "memory debugger" or "leak detector". There are hundreds of
them, just search the web.

> Is there any such like functions in the standard library?

No.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

shahav

unread,
Nov 28, 2009, 3:41:37 AM11/28/09
to
On Nov 27, 3:36 pm, blackbiscuit <infozyzh...@gmail.com> wrote:
> Dear all,
>
> In MSVC, there is some function called _CrtDumpMemoryLeaks which helps
> us to find the memory leak point in the source code. But may I ask if
> I were programming on Linux platform or Mac OS X, is there any similar
> way to detect the memory leak in the C++ source code? Is there any
> such like functions in the standard library?
>
> Thanks for your attention.
>
> Best wishes,
> Tony
>
> --
> [ Seehttp://www.gotw.ca/resources/clcm.htmfor info about ]

> [ comp.lang.c++.moderated. First time posters: Do this! ]

try valgrind - its a not a pinpoint app for memory leak, but a
comprehensive solution for memory issues, it is free and no recompile/
link is required, the penalty is in run time and used memory.
Rabin

KjellKod

unread,
Nov 28, 2009, 9:17:58 PM11/28/09
to
On Nov 28, 9:37 am, alapaa <erik.ala...@bredband.net> wrote:
> On Nov 27, 2:36 pm, blackbiscuit <infozyzh...@gmail.com> wrote:
>
> > Dear all,
>
> > In MSVC, there is some function called _CrtDumpMemoryLeaks which helps
> > us to find the memory leak point in the source code. But may I ask if
> > I were programming on Linux platform or Mac OS X, is there any similar
> > way to detect the memory leak in the C++ source code? Is there any
> > such like functions in the standard library?
>
> For Linux, Valgrind is great! But the last time I used it, it did only
> heap checks, not stack. There are commercial tools such as Rational
> Purify that can check both heap and stack, but Valgrind is free and it
> is a really useful tool. I know it works well for C, but I am not sure
> if it is as useful for C++.

{ edits: quoted sig & banner removed. please don't quote the banner. -mod }

For big systems(say 0.5 million lines of code or more) Valgrind can
unfortunately severely impact on the
performance - even up to the point where it is basically not possible
to run the system.

On these occasions I've used LeakTracer or a modified version of it.
LeakTracer has minimal impact on performance.
It's a little bit limited but have caught leaks that were found by
Valgrind

Good luck (and here's the link: http://www.andreasen.org/LeakTracer/)
/ Kjell Hedstr�m

Yongwei Wu

unread,
Nov 29, 2009, 2:05:58 PM11/29/09
to
On Nov 27, 9:36 pm, blackbiscuit <infozyzh...@gmail.com> wrote:
> Dear all,
>
> In MSVC, there is some function called _CrtDumpMemoryLeaks which helps
> us to find the memory leak point in the source code. But may I ask if
> I were programming on Linux platform or Mac OS X, is there any similar
> way to detect the memory leak in the C++ source code? Is there any
> such like functions in the standard library?

I have written a free memory debugger that may be of interest to you.
It is described in this page:

http://wyw.dcweb.cn/leakage.htm

One good thing about it is that you can use new(std::nothrow). Older
versions do not support it. It is also very efficient.

You can download it here:

http://sourceforge.net/projects/nvwa/files/

Best regards,

Yongwei

Vladimir Jovic

unread,
Nov 30, 2009, 9:21:50 AM11/30/09
to
KjellKod wrote:
> On Nov 28, 9:37 am, alapaa <erik.ala...@bredband.net> wrote:
>> On Nov 27, 2:36 pm, blackbiscuit <infozyzh...@gmail.com> wrote:
>>
>>> Dear all,
>>> In MSVC, there is some function called _CrtDumpMemoryLeaks which helps
>>> us to find the memory leak point in the source code. But may I ask if
>>> I were programming on Linux platform or Mac OS X, is there any similar
>>> way to detect the memory leak in the C++ source code? Is there any
>>> such like functions in the standard library?
>> For Linux, Valgrind is great! But the last time I used it, it did only
>> heap checks, not stack. There are commercial tools such as Rational
>> Purify that can check both heap and stack, but Valgrind is free and it
>> is a really useful tool. I know it works well for C, but I am not sure
>> if it is as useful for C++.
>
> { edits: quoted sig & banner removed. please don't quote the banner. -mod }
>
> For big systems(say 0.5 million lines of code or more) Valgrind can
> unfortunately severely impact on the
> performance - even up to the point where it is basically not possible
> to run the system.

It is still very useful to check memory leaks when running unit tests.


--
ultrasound www.ezono.com

Richard Corden

unread,
Nov 30, 2009, 9:20:49 AM11/30/09
to
{ this is getting too environment-specific. consider taking this
to the newsgroup dedicated to your OS. thanks. -mod }

alapaa wrote:
> On Nov 27, 2:36 pm, blackbiscuit <infozyzh...@gmail.com> wrote:
>> Dear all,
>>
>> In MSVC, there is some function called _CrtDumpMemoryLeaks which helps
>> us to find the memory leak point in the source code. But may I ask if
>> I were programming on Linux platform or Mac OS X, is there any similar
>> way to detect the memory leak in the C++ source code? Is there any
>> such like functions in the standard library?
>>
>
> For Linux, Valgrind is great! But the last time I used it, it did only
> heap checks, not stack.


You can partially check the stack (if using g++) with
"-fstack-protector-all". It adds some stack checking to functions.


Regards,

Richard

0 new messages