Memory leak of new in C++

Introduction to Memory Leaks

Memory leaks are common bugs that appear frequently. Memory leaks will cause the heap memory to be gradually occupied, and eventually the program will crash when the memory runs out. A common situation is that there is no problem with the project test, but it explodes within a few days of going online. Then it will be very troublesome, difficult to check, and the loss will be great.
Memory leak is one of the most serious errors. The program is not afraid of reporting an error, but it is afraid that it runs well at the beginning, and suddenly an inexplicable error occurs.

Detect memory leaks

Use VLD detection, how to introduce VLD, you can private message me.

We use this code to detect memory leaks

int* p1 = new int(100);

After introducing VLD, running a piece of normal code will show
insert image description here
that there is no memory leak problem.

After adding that line of code, an error will be reported when running
insert image description here

Guess you like

Origin blog.csdn.net/qq_63524016/article/details/129781695