我正在使用运行时库 CRT 来检测内存泄漏。这是我在析构函数中发现的:
_CrtMemCheckpoint(&crtMemStateFinish);
nDifference = _CrtMemDifference(&crtMemStateDifference, &crtMemStateStart, &crtMemStateFinish);
sizeChange = crtMemStateFinish.lSizes - crtMemStateStart.lSizes;
if(nDifference > 0)
_CrtDumpMemoryLeaks();
nDifference = 0;
sizeChange = 0;
_CrtMemCheckpoint(&crtMemStateStart);
delete[] ptr;
ptr = NULL;
_CrtMemCheckpoint(&crtMemStateFinish);
nDifference = _CrtMemDifference(&crtMemStateDifference, &crtMemStateStart, &crtMemStateFinish);
sizeChange = crtMemStateFinish.lSizes - crtMemStateStart.lSizes;
if(nDifference > 0)
_CrtDumpMemoryLeaks();
nDifference = 0;
sizeChange = 0;
_CrtMemCheckpoint(&crtMemStateStart);
nDifference > 0,所以有内存泄漏,但没有说在哪里。
以下是 ptr 的声明和定义方式:
char ** ptr;
ptr = new char*[4];
有什么建议么?