searching a function of standard libraries to help detecting memory leaks

Discussion in 'C++' started by Diego Martins, Oct 5, 2006.

  1. Hi all! I am doing a crude investigation of memory leaks in objects
    created by external libraries.
    Since I don't have access to the source code, I can't tell if an object
    are freeing its resources properly during destruction.

    For now, I need a portable function that can tell me the available free
    store memory. With that, I can do things like:

    size_t mem = getFreeStoreAvailable();
    {
    SuspiciousObject obj;
    ...
    } // obj destructor invoked here by compiler

    assert( mem == getFreeStoreAvailable() );


    of course it won't work for detecting resource leaks (e.g: handles)

    do you know this function? any ideas?

    Diego Martins
    HP
     
    Diego Martins, Oct 5, 2006
    #1
    1. Advertising

  2. Diego Martins wrote:
    > Hi all! I am doing a crude investigation of memory leaks in objects
    > created by external libraries.


    Welcome to the club!

    > Since I don't have access to the source code, I can't tell if an
    > object are freeing its resources properly during destruction.
    >
    > For now, I need a portable function that can tell me the available
    > free store memory.


    There is no such standard function. You either need to write your own,
    or use whatever mechanism your OS provides.

    > With that, I can do things like:
    >
    > size_t mem = getFreeStoreAvailable();
    > {
    > SuspiciousObject obj;
    > ...
    > } // obj destructor invoked here by compiler
    >
    > assert( mem == getFreeStoreAvailable() );
    >
    >
    > of course it won't work for detecting resource leaks (e.g: handles)


    No such thing in standard C++.

    >
    > do you know this function? any ideas?


    No such standard function. Try the newsgroup for your OS.

    Generally speaking, you _could_ measure it by allocating [in a loop]
    different amounts until you get a failure, followed by freeing all that
    you just allocated. However, that is not necessarily the true measure
    of the "available free store memory". Remember the "you change it if
    you measure it" principle? Ultimately, even if you have to call some
    function to measure the free store memory, you *could* change it, and
    the behaviour of the program *might* be different from if you didn't
    ask for the avaiable free store memory.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Oct 5, 2006
    #2
    1. Advertising

  3. Re: searching a function of standard libraries to help detectingmemory leaks

    Diego Martins wrote:
    > Hi all! I am doing a crude investigation of memory leaks in objects
    > created by external libraries.
    > Since I don't have access to the source code, I can't tell if an object
    > are freeing its resources properly during destruction.
    >
    > For now, I need a portable function that can tell me the available free
    > store memory. With that, I can do things like:
    >
    > size_t mem = getFreeStoreAvailable();
    > {
    > SuspiciousObject obj;
    > ...
    > } // obj destructor invoked here by compiler
    >
    > assert( mem == getFreeStoreAvailable() );
    >
    >
    > of course it won't work for detecting resource leaks (e.g: handles)
    >
    > do you know this function? any ideas?


    <OT>
    If you are working on a x86 I suggest using valgrind.
    It will detect memory leaks without the need to recompile
    (although you may wish to recompile with -g to obtain
    line-number information).
    </OT>

    HTH,
    - J.
     
    Jacek Dziedzic, Oct 6, 2006
    #3
  4. Diego Martins

    Osama Aouda Guest

    You might want to try Rational Purify. You can download it and try it
    for 15 days
    http://www-306.ibm.com/software/awdtools/purify/

    I do not work there ..Ok, I just used the tool, and it helped me to
    find memory leak.

    Good luck

    Osama Aouda

    Diego Martins wrote:
    > Hi all! I am doing a crude investigation of memory leaks in objects
    > created by external libraries.
    > Since I don't have access to the source code, I can't tell if an object
    > are freeing its resources properly during destruction.
    >
    > For now, I need a portable function that can tell me the available free
    > store memory. With that, I can do things like:
    >
    > size_t mem = getFreeStoreAvailable();
    > {
    > SuspiciousObject obj;
    > ...
    > } // obj destructor invoked here by compiler
    >
    > assert( mem == getFreeStoreAvailable() );
    >
    >
    > of course it won't work for detecting resource leaks (e.g: handles)
    >
    > do you know this function? any ideas?
    >
    > Diego Martins
    > HP
     
    Osama Aouda, Oct 7, 2006
    #4
  5. Osama Aouda wrote:
    > You might want to try Rational Purify. You can download it and try it
    > for 15 days
    > http://www-306.ibm.com/software/awdtools/purify/
    >
    > I do not work there ..Ok, I just used the tool, and it helped me to
    > find memory leak.
    >
    > Good luck
    >
    > Osama Aouda


    thanks. I'll use VLD

    it is a shame there is no portable way to achieve this :(
     
    Diego Martins, Oct 9, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ASP.Confused

    ASP.NET - Detecting memory leaks

    ASP.Confused, Jul 16, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,800
    Marina
    Jul 16, 2004
  2. Jive

    Detecting memory leaks

    Jive, Nov 21, 2004, in forum: Python
    Replies:
    2
    Views:
    398
    Eddie Parker
    Nov 21, 2004
  3. Ilias Lazaridis

    Detecting memory leaks on apache, mod_python

    Ilias Lazaridis, Dec 17, 2007, in forum: Python
    Replies:
    14
    Views:
    611
    Ilias Lazaridis
    Dec 23, 2007
  4. Sriram Srinivasan
    Replies:
    13
    Views:
    600
    Benjamin Kaplan
    Nov 12, 2009
  5. Jerome Sui

    detecting memory leaks in Perl

    Jerome Sui, Jul 13, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    141
    Jerome Sui
    Jul 13, 2003
Loading...

Share This Page