C + + memory leak detection

Source: Internet
Author: User

Using libraries to detect memory leak information

#define _CRTDBG_MAP_ALLOC//Without this macro definition, we can only know that there is a memory leak, but there is no way to know where to apply for memory forgot to release

#include <stdlib.h> #include <crtdbg.h>int main (void) {char *p = (char *) malloc (sizeof (char) * 100); _CrtDumpMemoryLeaks ();}

Using CRTDBG to detect a memory leak is simple, as long as you define _CRTDBG_MAP_ALLOC in the first line of the file, and then include the header file Crtdbg.h, call _CrtDumpMemoryLeaks where the program requires memory detection. Can output memory leak information, such as the above program, we have requested 100 bytes of memory and not released, but we can clearly see where the memory leaks

C + + memory leak detection

Related Article

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.