Process crash with high memory allocation

I am trying to find a significant memory leak (15 MB at a time, but I do such allocations in several places). I checked the most obvious places and then used AQTime, but I still can’t pinpoint this. Now I see 2 options:

1) Use SetProcessWorkingSetSize: I tried this, but my process happily continues to work when using more than 150 MB:

DWORD MemorySize = 150*1024*1024; SetProcessWorkingSetSize( GetCurrentProcess(), MemorySize/2, MemorySize*2 ); 

2) Place a breakpoint when allocating more than 1 MB at a time. How to do this, reload the new operator with "if> 1MB" inside?

+4
source share
6 answers

Sorry, none of the suggested solutions worked. Finally, it was fixed using AQTime and a lot of debugoutput. The leak was cleaned when turned off, so she was looking for a needle in a haystack.

However, I am interested in how to find this effectively. I tried to set a conditional breakpoint on a new statement, but the debugger took an age to evaluate "bytes> 1024 * 1024" for each individual distribution.

0
source

SetProcessWorkingSetSize does not mean what you think it means - it is the key to the OS about how much memory you need to store in memory, not on disk. Modern OSs are very aggressive when it comes to paging unused memory to disk - especially on Windows.

IBM Rational Purify is your only solution other than very thorough code analysis. On Windows for C / C ++, there is no better tool for finding memory leaks. On Mac or Linux, you can use valgrind, but AFAIK, it still does not work on Windows.

+1
source

Of your tags, you are using C ++ and visual studio.

In this case, you can simply use the crt debug hooks that Microssoft provides you with.

Find msdn for _CrtSetAllocHook.

In the debug assembly, this will allow you to intercept every selection - you can ignore small ones and just set a breakpoint or call :: DebugBreak on large ones.

+1
source

1) Use SetProcessWorkingSetSize: I tried this, but my process happily continues to work when using more than 150 MB:

What returns SetProcessWorkingSetSize? Is a call being made?

2) Place a breakpoint when allocating more than 1 MB at a time. How to do this, reload the new operator with "if> 1MB" inside?
Yes, that should work.

You may find it helpful to familiarize yourself with the tools provided by MSVC C Runtime Debug Heap .

0
source

In a system with an embedded type, we will do what you offer - a break in any call to new / memAlloc above a certain threshold and do the same on free / delete. It is tiring, but it will do the job. A specific breakpoint in size should do what you want, but when removed it is a little worse.

0
source

Try using UMDH . This is a free Microsoft utility that can detect memory leaks.

0
source

Source: https://habr.com/ru/post/1306720/


All Articles