1

I am following msdn article for finding memory leaks using CRT.

http://msdn.microsoft.com/en-us/library/x98tx3cf%28v=vs.100%29.aspx

I added _CrtDumpMemoryLeaks(); to the exit point of my application. It shows me thousands of memory leaks in different files. But I am interested in finding memory leaks of a particular file/class/function. Is there any possible way to implement this.

Here is what I tried to do.

void SomeClass::SomeRandomFunction(SomeRandomParameters)
{
    _CrtDumpMemoryLeaks();                 // Start of function.
    // Some lines of codes which may contain memory leaks.

    _CrtDumpMemoryLeaks();                 // End of function.
}

I added breakpoints on entry and exit of this method. I thought that second DumpMemory function will display only memory leaks which were find between these two DumpMemory function calls. But it didn't happened. Is there any other way to do this?

4

1 回答 1

4

_CrtDumpMemoryLeaks() 只能在程序结束时使用。您正在寻找的是 _CrtMemCheckpoint(),在函数开始时调用它来拍摄快照。并在函数末尾使用 _CrtMemDumpAllObjectsSince() 来查看自快照以来分配但未释放的内容。小心,当你把它做得这么细时,它们可能不一定是泄漏。

于 2013-05-21T10:52:15.227 回答