Recently in a project,ProgramMemory leakage occurs after exiting:
Detected memory leaks!
Dumping objects->
{98500} normal block at 0x05785ad0, 152 bytes long.
Data: <n N x 7> 3C AC 4E 10 00 00 00 00 BC A4 4E 10 78 B6 37 00
Object dump complete.
And every exit is the same. The leaked memory block is 98500.
Solution:
1. Use it in the place where the program starts (enough in front of the leaked memory allocation, such as in the constructor of the app class in a large project)Code:
_ Crtsetbreakalloc (98500); // 98500 indicates the block number leaked by the memory above.
2. Then debug the program, and the program's automatic breakpoint is in the "memory block 98500" Allocation position:
If (_ crtbreakalloc! =-1l & lrequest = _ crtbreakalloc)
_ Crtdbgbreak ();
3. We have found the leaked underlying memory allocation operation (good memory !).
At this time, we use "debug"-> "exit". The shortcut key is "Shift + F11 ".
Jump out of the current function... then jump to "up" and view the call stack while jumping until you see your own code, such as my
STD: ifstream * origstream = new STD: ifstream ();
4. At this time, I can determine that origstream has allocated memory, but it has not been properly released. After processing it again, there will be no memory leakage.
5. In the end, remember to delete the _ crtsetbreakalloc (98500); statement. Otherwise, it will not be annoying to have a breakpoint every time ..
Bytes ----------------------------------------------------------------------------------------------------------
Written below:
There is a visual Leak Detector for Memory leakage detection. According to its introduction, it is really good. You can directly identify the memory leakage in the code line, but I personally used it, I found that the debug speed is too slow. I don't know if it is a problem with my personal program ....... like the above leakage, a simple method like crtsetbreakalloc is enough ....