Thread: Finding the elusive memory leak...

  1. #1
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250

    Finding the elusive memory leak...

    Now I have a project, which is in total 4-5k lines of code, and am now leaking 24 bytes one time when I close. I've narrowed down the size to a custom struct I made. However, for all you debugging junkies out there, is it a good idea to go on this memory size as reported by MSVC 2003 .net? Or is this only a small guide to let me know there is a leak somewhere. I know this is a rather nebulous question but any theories would be helpful.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You can use the functionality provided by visual studio inside of crtdbg.h

    Here is a link:
    http://www.thinkingms.com/pensieve/h...orld_debug.htm

    Simple and effective. If you have the money to throw around I strongly recommend BoundsChecker.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Hm I've never used crtdbg.h before. I tried that out and it seems that it flags memory leaks for classes that cleanup in their destructor (like std::vector) I guess that makes sense, but what's the best way to deal with that? Maybe just explicitly calling the destructor before _CrtDumpMemoryLeaks(); ...?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Quote Originally Posted by JaWiB
    Hm I've never used crtdbg.h before. I tried that out and it seems that it flags memory leaks for classes that cleanup in their destructor (like std::vector) I guess that makes sense, but what's the best way to deal with that? Maybe just explicitly calling the destructor before _CrtDumpMemoryLeaks(); ...?
    Make sure everything is destructed by the time _CrtDumpMemoryLeaks() is called by removing global variables, introducing an extra scope, moving code to a separate function, or whatever you need to do. Don't explicitly call the destructor, though.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    19
    well,

    this is very imp info regarding memory leaks.

    thanks for this.

    and keep it up.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex and Shared Memory Segment Questions.
    By MadDog in forum Linux Programming
    Replies: 14
    Last Post: 06-20-2010, 04:04 AM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  3. Memory leak with detached pthreads - how to free?
    By rfk in forum Linux Programming
    Replies: 2
    Last Post: 08-17-2007, 06:50 AM
  4. Huge memory leak
    By durban in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2005, 12:10 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM