Skip to main content
gamedev.net
🔒 Locked

Memory Leaks

Started by Mike.Popoloski Oct 18, 2005 at 3:37 PM 5 replies 500+ views
Original Post
Mike.Popoloski
Mike.Popoloski
Does anyone know if there is a way to detect if your program is leaking memory?
Mike Popoloski | Journal | SlimDX
rip-off
rip-off
im using c++, so i've overloaded new and delete, new[] and delete[];

using new or new[] increments a certain count variable( one for each ), and delete and delete[] decrements it.

then i have a function that logs the un-deallocated counts, and using atexit( ); i make it the last function called. i have no global objects, so it should be the lst thing executed.

works for me but is plain ugly. bascially whenever i change something and there are un-deallocated pointers i know where to look. wouldnt be much help on an existing project with a huge number of files.
Saandman
Saandman
If you're using C/C++ you could use the built in functions.

#define _CRTDBG_MAP_ALLOC
#include
#include

Then in the end:
_CrtDumpMemoryLeaks();

If you're involved in a larger project, you might want to check out payware memory leak detectors though.
________pro.gram.mer - an organism that turns caffeine into code
rip-off
rip-off
Quote:
Original post by Saandman
If you're using C/C++ you could use the built in functions.

#define _CRTDBG_MAP_ALLOC
#include
#include

Then in the end:
_CrtDumpMemoryLeaks();

If you're involved in a larger project, you might want to check out payware memory leak detectors though.


"built in functions."

are these Microsoft visual c++ built in functions, because my Dev-Cpp doesnt have them and im trying to remain cross platform...
Saandman
Saandman
Ops sorry mistake on my part there, not everyone is using msvc =)
________pro.gram.mer - an organism that turns caffeine into code
intransigent-seal
intransigent-seal
Get the Fluid Studios Memory Manager. It will track memory allocations, and give you a list of any blocks that you haven't freed at the end of your program (ie, leaks).

Edit: Also, you may want to skim this thread.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.