Detecting Memory Leaks
From C4 Engine Wiki
The C4 Engine has a built-in mechanism for detecting memory leaks. Memory leak is the term used when a block of memory allocated at some point in a program's execution is not properly released before the program exits. Sometimes, the same memory leaks recur over and over again while a program runs and eat up more and more memory, possibly leading to performance problems. It's good practice to make sure that memory allocations are always released when they are no longer needed.
The following code appears near the top of the file C4Memory.h.
#if C4DEBUG #define C4MEMDEBUG 1 #define C4LEAK_DETECTION 0 #else #define C4MEMDEBUG 0 #define C4LEAK_DETECTION 0 #endif
To turn on memory leak detection, define LEAK_DETECTION to be 1 for either the debug build or optimized build and recompile. (MEMDEBUG must also be 1 for leak detection to work.) Then, every time the engine is run, it will track memory allocations made for each use of the C++ new operator and the corresponding deallocations for each use of the delete operator. While this is turned on, you should thoroughly exercise any code paths that you wish to test and then exit the engine normally.
Right before the engine exits, it will create a file called Leaks.txt and place it in the same directory as the C4.exe application. Inside the file will be a list of the different memory heaps that were in use while the engine ran. For each heap, a list of unreleased memory blocks will be listed with their size and the specific file and line where they were originally allocated. This information can be used to track down and eliminate leaks by adding the appropriate code to release abandoned blocks of memory. If the file does not list any leaked blocks, then everything was properly released.
