Memory leak in a multithreaded C ++ application on Linux

We have a large multithreaded C ++ application running on Linux. We see that the occupied memory of the application is growing rapidly and believes that there are some leaks. We tried every tool we have (valgrind, DynLeak, Purify), but found nothing. Since this application can run on Windows, we also tried Bounds Checker. It didn’t help either.

We need a new tool that can help. I looked at Google Perfomrance Tools, MMGR Paul Nettle, MemCheck Deluxe. None of them impressed me.

Is there a good tool somewhere for this task?

+4
source share
3 answers

The definition of a memory leak in C / C ++ is very specific: it is the memory that was allocated and then the pointer was overwritten or otherwise lost. Valgrind usually detects such cases out of the box, but it's not always that simple.

  • Your application can use this memory very well. In this case, you may have a Java programmer consider a leak, for example. entering data into the structure and rarely (or never) deleting records.

  • Perhaps you are measuring the memory usage in your memory incorrectly. In terms of memory usage, Linux is not as straightforward as it seems. How did you measure memory usage?

  • You should consider using the application hooks (Valgrind calls them client requests ) of any memory analysis tool that you use to avoid the problem of reports that are issued only when the program terminates. Using these hooks can help you locate the leak.

  • You should try using a heap profiler like massif from Valgrind to look for memory allocation locations with an excessive amount of allocated memory.

  • Make sure you are not using a custom allocator or garbage collector in your application. As far as I know, the memory analysis tool will not work with a user allocator without user interference .

  • If the memory leak is large enough to be detected within an acceptable runtime of the application, you can try to perform a binary search of old versions through your version control system to identify the commit that introduced the problem. At least Mercurial and Git offer built-in support for this task.

+5
source

If "did not help", you mean that he did not report a memory leak, it is possible that you do not have it, and just use more and more memory, which is still referenced by pointers, and you can delete them.

+2
source

To help you debug the problem, perhaps in your protocol, you should also indicate the size of the memory, the number of objects (their type) and several other statistics that are useful to you. At least until you get comfortable with the tools you mentioned.

+1
source

All Articles