I got a memory leak (55 bytes) on my program like this. I am using C++, MFC, Visual Studio 2010.
Detected memory leaks! {13497} normal block at 0x0E44C248, 55 bytes long. Data: 44 3A 5C 46 44 41 53....
the problem is, the memory allocation number "13497" is not always same. it's always different number if I run the program again. I wanted to find where I didn't release the memory before the exit, with _crtBreakAlloc, but it seems not possible to break on a memory allocation number. I used _CrtSetDbgFlag, and _CrtDumpMemoryLeaks as well, but it also didn't work well.
Is there any way to detect the memory leak in this case?
Thank you.
Hello thanks for your answers..
I found the leak location very easily by using "Visual Leak detector" from https://vld.codeplex.com/ I strongly recommend this one to those who have the same problem. :) you can just download it and put it in your project.
You can use a static analizer like cppcheck or, as Joe said, remap operator
new
.I developed some memory leaks utilities that you can use:
https://github.com/check69/Utils/blob/master/leaks.cpp
https://github.com/check69/Utils/blob/master/leaks.h
There is some visual studio instruction to get the leaks in the console output, to debug easier.
PS: I would put this as a comment in joe post, but I need 50 points to put comments.
Well there are a few ways to attack this.
This code remaps operator new