How to locate C ++ Memory leakage and vs2017 leakage in vs2017

Source: Internet
Author: User

How to locate C ++ Memory leakage and vs2017 leakage in vs2017

Locating memory leaks is a tricky issue in C ++. One of the feasible methods is as follows:

// Add the following code to the main function file # include <stdlib. h> # include <crtdbg. h> # ifdef _ DEBUG # define new (_ NORMAL_BLOCK, _ FILE __, _ LINE _) # endif void EnableMemLeakCheck () {int tmpFlag = _ CrtSetDbgFlag (_ CRTDBG_REPORT_FLAG); tmpFlag | = _ blank; _ CrtSetDbgFlag (tmpFlag);} using namespace std; int main () {EnableMemLeakCheck (); // _ CrtSetBreakAlloc (comment out the first time and execute the second time); your own code}

In debug mode, the following information is displayed in the output:

Note the content in braces {}. Here is {156}. This is where the program memory may be leaked.

Add the Code Annotated above and fill in the numbers in braces so that the program can be stopped at the place where the memory leaks.

As shown in the following figure, here I park the program at 156:

// Add the following code to the main function file # include <stdlib. h> # include <crtdbg. h> # ifdef _ DEBUG # define new (_ NORMAL_BLOCK, _ FILE __, _ LINE _) # endif void EnableMemLeakCheck () {int tmpFlag = _ CrtSetDbgFlag (_ CRTDBG_REPORT_FLAG); tmpFlag | = _ blank; _ CrtSetDbgFlag (tmpFlag);} using namespace std; int main () {EnableMemLeakCheck (); _ CrtSetBreakAlloc (156); your own code}

Reference: https://www.cnblogs.com/luruiyuan/p/6916634.html

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.