2012-01-12 72 views
-3

可能重复:
How to Test for Memory Leaks?
how to find memory leak in c++ code/project
How to find a memory leak in C++
Is there a good Valgrind substitute for Windows?查找内存的最佳解决方案泄漏

我有我的C++程序有很多内存泄漏。什么是解决方案(程序)来找到它们?

+2

请勿使用C++。对不起,无法抗拒:-D – 2012-01-12 11:01:47

+5

@Thorsten:不,真正的snarky评论是“不要使用'new'”。 – 2012-01-12 11:02:54

+0

[如何测试内存泄漏?](http://stackoverflow.com/questions/420599/how-to-test-for-memory-leaks),[是否有良好的Valgrind替代Windows?] (http://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows) – 2012-01-12 11:04:12

回答

1

对于哪个操作系统?

在基于Linux的系统上,Valgrind。自由。

在基于Windows的系统上,Insure ++,Purify ....很多。

4

我喜欢用valgrind。假设g++clang++,与-g编译程序,并尝试:

valgrind --leak-check=full ./your_executable 
2

最好的解决方案是实现现代化的计划。

  1. 在您的程序中搜索newdelete
  2. 更新您的程序以使用智能指针。到处。
  3. 完成后引入泄漏将是“非常困难”,如果你做得对。

如果你在OS X man leaks,泄漏Instrument或valgrind。随着程序的现代化,您可以使用这些来观察泄漏计数下降;)