目前只知道这个工具可以测试linux下的内存泄漏问题,很好用,下载地址是http://www.valgrind.org/downloads/valgrind-3.8.1.tar.bz2
安装:
[root@localhost ~]# cd valgrind-3.8.1
[root@localhost valgrind-3.8.1]# ./configure && make && makeinstall
完成后
进行测试看是否安装成功。
[ubuntu@root ~]#valgrind
看结果是否为:
[ubuntu@root ~]#valgrind
valgrind: no program specified
valgrind: Use --help for more information.
然后就可以对程序就行了测试了:
测试:
3、示例(测试一个C)
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct mm{
int a;
int b;
}kk,*p;
kk.a = 10;
printf("kk.a : %d \n",kk.a);
p = (struct mm *)malloc(sizeof(struct mm));
p->a = 9;
printf("p->a : %d \n",p->a);
return 0;
}
操作如下:
[root@localhost ~]# vim hello.c
[root@localhost ~]# gcc -g -o hello hello.c
[root@localhost ~]# ./hello
结果如下:
然后用valgrind命令:
[root@localhost ~]# valgrind --tool=memcheck--leak-check=yes --show-reachable=yes ./hello
可以看出上面提示“malloc/free:1 allocs, 0 frees, 8 bytes allocated.”,“definitely
lost:8 bytes in 1 blocks.”。即丢失了8个字节。例子引用了其他人的。。。。。
这个工具不错,对于开发arm上这种比较需要注意资源使用的程序,很有帮助