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