• 6294阅读
  • 2回复

Qt程序的内存泄漏 [复制链接]

上一主题 下一主题
离线wato
 
只看楼主 倒序阅读 楼主  发表于: 2010-04-07
以前一直对QT的内存管理机制很放心,所以没去关心过这个问题;最近看到论坛上有这方面的问题,突然想看看情况到底怎么样。

随便选了个以前学习时写的QT程序,在PC上用valgrind测试了几次,结果如下:

LEAK SUMMARY:
==18153==    definitely lost: 12,944 bytes in 57 blocks
==18153==    indirectly lost: 29,852 bytes in 1,462 blocks
==18153==      possibly lost: 1,063,186 bytes in 3,922 blocks
==18153==    still reachable: 427,914 bytes in 7,349 blocks
==18153==         suppressed: 0 bytes in 0 blocks


LEAK SUMMARY:
==18157==    definitely lost: 12,944 bytes in 57 blocks
==18157==    indirectly lost: 29,852 bytes in 1,462 blocks
==18157==      possibly lost: 1,063,306 bytes in 3,923 blocks
==18157==    still reachable: 427,922 bytes in 7,343 blocks
==18157==         suppressed: 0 bytes in 0 blocks



LEAK SUMMARY:
==18160==    definitely lost: 12,944 bytes in 57 blocks
==18160==    indirectly lost: 29,792 bytes in 1,459 blocks
==18160==      possibly lost: 1,059,772 bytes in 3,911 blocks
==18160==    still reachable: 429,788 bytes in 7,331 blocks
==18160==         suppressed: 0 bytes in 0 blocks

看着挺吓人的,不太明白这个still reachable到底代表什么意思,有经验的兄弟帮忙分析分析。
[ 此帖被wato在2010-04-07 09:43重新编辑 ]
离线wato
只看该作者 1楼 发表于: 2010-04-07
看来很多调试工具都认为那些有父亲的孩子没有被释放   Qt的高级机制反而导致它的程序没有调试工具可用了
离线steinlee

只看该作者 2楼 发表于: 2010-04-07
Still reachable may mean that some pointers are allocated, but not freed when the code is finished.
Generally speaking, it is not a problem. But it is a good habit to clear all heap memories by yourself.
Check the link here: http://valgrind.org/docs/manual/mc-manual.html

run valgrind --leak=full your code
you can find where the problems are.

type valgrind --help to find more options(--help is standard and works for other tools too)
[ 此帖被steinlee在2010-04-07 11:28重新编辑 ]
Looking for remote C/C++ and Qt 兼职
快速回复
限100 字节
 
上一个 下一个