Simple Memory Leak Detection solution for detected memory leaks

Source: Internet
Author: User

Simple Memory Leak Detection solution for detected memory leaks!

(14:16:07)

Reprinted token
Tags:

Detect memory leakage

 

Miscellaneous
Classification: Compiler

In a recent project, memory leakage occurs after the program exits:

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 the code at the place where the program starts (before enough, as long as it is in front of the leaked memory allocation, for example, in the constructor of the app class in a large project:

_ 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 ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.