VS下检测内存泄漏方法:
#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
//在入口函数中包含
_CrtDumpMemoryLeaks();
//即可检测到内存泄露
//以如下测试函数为例:
int main() {
char* pChars = new char[10];
//delete[]pChars;
_CrtDumpMemoryLeaks();
system("pause"); return 0; }
解决方法: