Troubleshooting memory Leaks in VC + + programs

Source: Internet
Author: User

Just learned today, how to quickly and accurately view the memory leak, immediately use the project ~ ~ ~

Using _CrtDumpMemoryLeaks, this function in the crtdbg.h header file, the General VC + + program can be directly referenced. Crtdumpmemoryleaks () is a display of the current memory leak. Note "Current" means that when it executes, all objects that are not destroyed are reported as memory leaks. If you want to check whether the program has a memory leak, try to put this function back to the surface, if it is to check the contents of the pointer is completely released, you can write after the release ~ ~

Of course this is used in debug mode, The CRT will record the file name and line number and size of the previously allocated memory, and when it calls _CrtDumpMemoryLeaks (), it will print if it has not been released.

The results are as follows: detected memory leaks! Dumping Objects->f:\test\memleakchecker\memleakchecker\memleakchecker.cpp (): {108} normal block at 0x0003a1a8, Ten bytes long. Data: < > CD CD CD CD CD CD CD CD F:\test\memleakchecker\memleakchecker\memleakchecker.cpp ($): {107} Client Block at 0x0003a160, subtype 0, bytes long. Data: < > CD CD CD CD CD CD CD CD F:\test\memleakchecker\memleakchecker\memleakchecker.cpp (+): {106} Client Block at 0x0003a120, subtype 0, 1 bytes long. Data: < > Object dump complete. It's easy to see where the memory is allocated and not released.

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.