• 5087阅读
  • 1回复

QT 内存管理问题 [复制链接]

上一主题 下一主题
离线mecland
 
只看楼主 倒序阅读 楼主  发表于: 2009-04-30
写一个最简单的QT程序(使用设计器建立一个窗体, 程序不做任何事件, 仅显示此窗口), 用valgrind调试信息如下:
==21745== ERROR SUMMARY: 668 errors from 35 contexts (suppressed: 16 from 5)
==21745== malloc/free: in use at exit: 124,119 bytes in 3,798 blocks.
==21745== malloc/free: 44,968 allocs, 41,170 frees, 7,929,110 bytes allocated.
==21745== For counts of detected errors, rerun with: -v
==21745== Use --track-origins=yes to see where uninitialised values come from
==21745== searching for pointers to 3,798 not-freed blocks.
==21745== checked 467,768 bytes.
==21745==
==21745==
==21745== 20 bytes in 1 blocks are definitely lost in loss record 24 of 84
==21745==    at 0x4023B58: malloc (vg_replace_malloc.c:207)
==21745==    by 0x4C7DADF: strdup (in /lib/libc-2.5.so)
==21745==    by 0x4194360: (within /usr/lib/libQtGui.so.4.2.1)
==21745==    by 0x413D8E8: QApplicationPrivate::construct(_XDisplay*, unsigned long, unsigned long) (in /usr/lib/libQtGui.so.4.2.1)
==21745==    by 0x413E6D2: QApplication::QApplication(int&, char**, int) (in /usr/lib/libQtGui.so.4.2.1)
==21745==    by 0x804A1FC: main (in /home/qt-baogao-source/test/test)
==21745==
==21745==
==21745== 225 bytes in 10 blocks are definitely lost in loss record 54 of 84
==21745==    at 0x4023B58: malloc (vg_replace_malloc.c:207)
==21745==    by 0x4810617: FcStrCopy (in /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x4813B52: (within /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x4D53145: (within /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4D53DCC: (within /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4D54E83: (within /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4D55D54: (within /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4D4D5CA: XML_ParseBuffer (in /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4812E2B: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x4813132: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x4813534: (within /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x4D53145: (within /usr/lib/libexpat.so.1.5.0)
==21745==
==21745==
==21745== 1,628 (1,408 direct, 220 indirect) bytes in 11 blocks are definitely lost in loss record 71 of 84
==21745==    at 0x4023B58: malloc (vg_replace_malloc.c:207)
==21745==    by 0x480E0D3: (within /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x480E9E3: (within /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x480EAE7: (within /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x4813A6F: (within /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x4D53145: (within /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4D53DCC: (within /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4D54E83: (within /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4D55D54: (within /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4D4D5CA: XML_ParseBuffer (in /usr/lib/libexpat.so.1.5.0)
==21745==    by 0x4812E2B: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.1.0)
==21745==    by 0x4813132: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.1.0)
==21745==
==21745== LEAK SUMMARY:
==21745==    definitely lost: 1,653 bytes in 22 blocks.
==21745==    indirectly lost: 220 bytes in 11 blocks.
==21745==      possibly lost: 0 bytes in 0 blocks.
==21745==    still reachable: 122,246 bytes in 3,765 blocks.
==21745==         suppressed: 0 bytes in 0 blocks.
==21745== Reachable blocks (those to which a pointer was found) are not shown.
==21745== To see them, rerun with: --leak-check=full --show-reachable=yes

感觉好象有泄漏, valgrind还不太会用. 另外一个弱智的问题, 使用UI文件生成的UI类中仅new了控件并没有delete它, 会不会有泄漏. 我手动在自己继承的类的析构函数中delete它并没有出错呀?
离线fcymk2

只看该作者 1楼 发表于: 2009-04-30
当销毁父窗口后会 自动销毁所有的子控件.所以不会泄漏的
快速回复
限100 字节
 
上一个 下一个