简体   繁体   English

Linux上的多线程C ++应用程序中的内存泄漏

[英]Memory leak in multi-threaded C++ application on Linux

We have a big multi-threaded C++ application running on Linux. 我们有一个在Linux上运行的大型多线程C ++应用程序。 We see that occupied by the application memory grows fast and believe there are some leaks. 我们看到应用程序内存占用的速度越来越快,并且相信存在一些泄漏。 We have tried every tool we have (valgrind, DynLeak, Purify) but did not find anything. 我们已经尝试了我们拥有的每一种工具(valgrind,DynLeak,Purify),但没有找到任何东西。 Since this application can run on Windows, we have also tried Bounds Checker. 由于此应用程序可以在Windows上运行,我们还尝试了Bounds Checker。 Did not help, too. 也没有帮助。

We need a new tool that can help. 我们需要一种可以提供帮助的新工具。 I've looked at Google Perfomrance Tools, MMGR by Paul Nettle, MemCheck Deluxe. 我查看了Google Perfomrance Tools,MMGR by Paul Nettle,MemCheck Deluxe。 None of them impressed me. 他们都没有给我留下深刻印象。

Is there anywhere a good tool for this task? 这个任务有什么好的工具吗?

The definition of a memory leak in C/C++ is very specific: it is memory that has been allocated and then the pointer was overwritten or otherwise lost. C / C ++中内存泄漏的定义非常具体:它是已分配的内存,然后指针被覆盖或以其他方式丢失。 Valgrind generally detects such cases out of the box, but things are not always that simple. Valgrind通常会开箱即用,但事情并非总是如此简单。

  • Your application could very well be still using that memory. 您的应用程序很可能仍在使用该内存。 In that case you might have what a Java programmer would consider a leak, eg entering data in a structure and rarely (or never) removing entries. 在这种情况下,您可能拥有Java程序员认为泄漏的内容,例如在结构中输入数据而很少(或从不)删除条目。

  • You might be measuring the memory usage of your memory incorrectly. 您可能错误地测量了内存的内存使用情况。 On Linux memory usage measurements are not as straight-forward as they seem. 在Linux上,内存使用量测量并不像它们看起来那么简单。 How have you measured your memory usage? 你是如何衡量你的内存使用量的?

  • You should consider using the application hooks (Valgrind calls them client requests ) of whatever memory analysis tool your are using, to avoid the issue with reports only being issued at program termination. 您应该考虑使用您正在使用的任何内存分析工具的应用程序挂钩(Valgrind称之为客户端请求 ),以避免报告仅在程序终止时发出的问题。 Using those hooks might help you pin-point the location of your leak. 使用这些钩子可能会帮助您精确定位泄漏的位置。

  • You should try using a heap profiler, such as massif from Valgrind, to look for memory allocation locations with inordinate amounts of allocated memory. 你应该尝试使用堆分析器,如地块从Valgrind的,以寻找与无节制的数量分配内存的内存分配位置。

  • Make sure you are not using a custom allocator or garbage collector in your application. 确保您的应用程序中没有使用自定义分配器或垃圾收集器。 As far as I know, no memory analysis tool will work with a custom allocator without user interference . 据我所知,没有内存分析工具可以在没有用户干扰的情况下使用自定义分配器。

  • If your memory leak is massive enough to be detectable within an acceptable amount of application run-time, you could try a binary search of old revisions 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. 至少MercurialGit为此任务提供内置支持。

如果“没有帮助”你的意思是它没有报告内存泄漏,很可能你没有它,只是使用越来越多的内存,仍然被指针引用,可以删除。

To help you debug the problem, perhaps in your logging, you should also write memory size, number of objects (their type) and a few other stats which are useful to you. 为了帮助您调试问题,可能在您的日志记录中,您还应该编写内存大小,对象数量(类型)以及一些对您有用的其他统计信息。 At least until you become more familiar with the tools you mentioned. 至少在你更熟悉你提到的工具之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM