Archived

This topic is now archived and is closed to further replies.

tscott1213

Global Memory Leak Tracer

Recommended Posts

I am trying to implement a technique for tracking memory leaks that was reviewed in a tutorial on flipcode that overrides the global definitions of new and delete to track memory allocation and deallocation. The code below illustrates the key changes to stdafx.h that overrides the definitions of new and delete. The changes are working for the file in which I included stdafx.h but it is not taking effect in any of the other files. Does anyone know what I am doing wrong, that the change is not globally effecting the entire program across all of the files? Thanks #ifdef _DEBUG void * operator new(unsigned int size, const char *file, int line) { void *ptr = (void *)malloc(size); AddTrack((DWORD)ptr, size, file, line); return(ptr); }; void __cdecl operator delete(void *p) { RemoveTrack((DWORD)p); free(p); }; #endif #ifdef _DEBUG #define DEBUG_NEW new(__FILE__, __LINE__) #else #define DEBUG_NEW new #endif #define new DEBUG_NEW

Share this post


Link to post
Share on other sites
Yes, it is before all of my included files, but it still is only working on the calls to new and delete that are in the actual file that includes the "stdafx.h" header.

Wierd.

Share this post


Link to post
Share on other sites
i attempted something like this before, and i can''t remember whether it was iostream.h or stdio.h that caused it to be very messed up. maybe check those?

Share this post


Link to post
Share on other sites