linux
查看/proc/pid/smaps,看heap总共用了多少,要是比预期用多了,就存在内存泄露的可能
1. 内存是否全部释放
a)正常启动程序,
b)正常关闭程序
查看是否有内存泄露
2. 异常情况下,中断程序
a)正常启动程序,
b)异常关闭程序
查看是否有内存泄露
3. 存在cache等干扰,
关闭cache
4. valgrind 显示解析
==19602== HEAP SUMMARY:
==19602== in use at exit: 3 bytes in 3 blocks
==19602== total heap usage: 1,000 allocs, 997 frees, 1,000 bytes allocated
1 bytes = sizeof(char),即一个字节
1K = 1000字节
1M = 1000 * 1000 字节
1G = 1000 * 1000 * 1000字节
解析例子
==22277== HEAP SUMMARY:
==22277== in use at exit: 3,000,000 bytes in 3 blocks
==22277== total heap usage: 1,000 allocs, 997 frees, 1,000,000,000 bytes allocated
程序退出时,还有3M(3,000,000 bytes)没有释放
5. malloc申请一个字节
malloc(sizeof(char)) == malloc(1);
阅读(831) | 评论(0) | 转发(0) |