Results 1 to 4 of 4

Thread: Trace Memory Leak

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Posts
    130
    Good day, everybody...
    I was wondering... how do I trace my program's memory leak, which is written in Visual C++? In other words, it's there any tool that is available for me to used to trace memory leakage?

    Thank you...

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If you run it in the debugger, when your program finishes it makes a list of all memory leaks.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Posts
    130
    Thanks parksie...

    Yeah, I discover this when i'm running in debug mode...

    The problem is it doesn't really pin-point the place/statement that the leak happen...

    I know I can sometimes trace back the pointers that I didn't deallocate.... but when a pointer is NULL, I can't really know which pointer is causing the leak...

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What I've done before is to, whenever I use new, to output using cerr the location of the memory area, and the location of the pointer variable, like so:
    Code:
    int *pPtr = new int[50];
    cerr << "Allocated " << (long)(&pPtr) << " pointing to " << (long)pPtr << " at " << __FILE__ << ":" << __LINE__ << endl;
    Not sure if that's totally correct, but you get the idea
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width