IntroductionHave you ever had a memory leak? Wished you knew where you allocated it and how? Is your boss cheap and refuses to buy Boundchecker or another debugging tool? Here is the solution for you. A memory leak detector compiled directly into your code. It reports memory leaks with call stack of the allocation down to a user defined depth. As an add-on, it does simple checks of the memory before and after the memory block, to track buffer overwrites. UsageInclude tracealloc.cpp in your project. Define You can find further instructions in the source code. How is it done?The code overrides operator When a memory block is deleted, the header is found and checked for buffer overwrites. The memory block is then removed from the linked list and deallocated. When the program terminates, the global memory tracker object is deleted. The destructor traverses the linked list for memory blocks that isn’t deleted (= leaked memory). It then fetches symbol information for the call stacks and dumps the information in the debug console. LimitationsThe code is Microsoft Visual Studio and Win32 specific. It requires a debug build. The code is C++ specific. It handles FinallyI want to thank Zoltan Csizmadia who wrote I also want to thank the Code Project community. I have found many solutions or pointers in the right direction here. I hope I have given something back with this contribution. Thank you! |
|