开发者

Breaking when a certain amount of bytes is allocated

开发者 https://www.devze.com 2023-01-26 07:26 出处:网络
_CrtDumpMemoryLeaks(); if you didn\'t know, is a function that dumps all the memory leaks in a program. Mine currently displays that I have a3632062 byte memory leak (it\'s not being deallocated).

_CrtDumpMemoryLeaks(); if you didn't know, is a function that dumps all the memory leaks in a program. Mine currently displays that I have a 3632062 byte memory leak (it's not being deallocated).

I was wondering: Is there any way to cause Visual C++ Express to break when a certain amount of bytes has been allocated? That way I could break when 3632062 bytes have been allocated, then read the stack trace to see where I allocated it.

This is currently the only method I can think of for finding where the memory is being allocated so I can fix it. I've been sear开发者_如何转开发ching my code a lot but I can't find anywhere where I would need to allocate 3632062 bytes (since the only file I load is 2767136 bytes..) although I am certain the leak is related to the file I'm operating on.

Any ideas for finding the source of the memory leak? I'm using Native C++, Visual C++ 2010


You could do this using _CrtSetAllocHook to track the total memory usage.

UMDH will give you a list of allocated blocks in all heaps. This might be what you want, since breaking on hitting a given total alloc threshold will not tell you where all of the blocks were allocated.


I have previously used this simple memory leak detector with good success for finding memory leaks.

0

精彩评论

暂无评论...
验证码 换一张
取 消