问题描述
我需要一个工具来帮助我以类似valgrind的方式查找c程序中的内存泄漏.它应该指出程序何时不应该覆盖内存(例如,通过错误地计算数组索引).我了解到,图形工具应用程序中包含泄漏实用程序.
I need a tool which helps me to find memory leaks in a c program in a similar way valgrind does. It should figures out when a program overwrites memory it should not (e.g. by miscalculating an array index). I learned that there is the leaks utility along with the graphical instruments app.
但是,我认为它只能找到分配有新的(或malloc)的内存,而该内存尚未释放且不再可访问.我还了解到valgrind应该可以在较旧的版本(10.5和10.6)上运行,但我使用的是狮子(10.7).
However I think it can just find memory allocated with new (or malloc) which was not released and is not accessible anymore. Also I learned that valgrind is supposed to work on older releases (10.5 and 10.6), but I use lion (10.7).
推荐答案
我将使用XCode开发人员工具 MallocDebug .您应该在/Developer 文件夹中将其与XCode一起安装
I would use the XCode developer tool MallocDebug. You should have this installed with XCode in your /Developer folder
或者,您可以在 gdb 中运行应用程序,并通过运行
Alternatively, you can run your application in gdb and use the native malloc logging by running
% gdb <program name>
(gdb) set env MallocStackLoggingNoCompact 1
(gdb) run
然后,您可以使用/usr/bin/leaks
和/usr/bin/malloc_history
查找明显的泄漏
Then, you can use /usr/bin/leaks
and /usr/bin/malloc_history
to find obvious leaks
这篇关于Mac OS 10.7(Lion)上的类似Valgrind的工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!