PDA

View Full Version : Qt Memory manager



bunjee
18th August 2009, 08:51
I'd like to track memory leaks in my application.

Anybody ever coded a Qt MemoryManager class?

Thanks.

spirit
18th August 2009, 09:08
try to use valgrind (http://valgrind.org/) on Linux.

PaceyIV
18th August 2009, 10:38
I was familiar with mcheck of libc. (http://www.gnu.org/software/libc/manual/html_node/Allocation-Debugging.html#Allocation-Debugging)

I try valgrid with my project but I am a little confused.
I found just a memory leaky that I made in my code. But there is a lot of memory leaky in the Qt library :(



==6190== Memcheck, a memory error detector.
==6190== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==6190== Using LibVEX rev 1884, a library for dynamic binary translation.
==6190== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==6190== Using valgrind-3.4.1-Debian, a dynamic binary instrumentation framework.
==6190== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==6190== For more details, rerun with: -v
==6190==
==6190==
==6190== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 163 from 4)
==6190== malloc/free: in use at exit: 246,896 bytes in 5,239 blocks.
==6190== malloc/free: 267,157 allocs, 261,918 frees, 48,167,856 bytes allocated.
==6190== For counts of detected errors, rerun with: -v
==6190== searching for pointers to 5,239 not-freed blocks.
==6190== checked 910,728 bytes.
==6190==
==6190== 2 bytes in 1 blocks are definitely lost in loss record 2 of 127
==6190== at 0x4025092: calloc (vg_replace_malloc.c:397)
==6190== by 0x4D1AA92: _hb_alloc (harfbuzz-impl.c:41)
==6190== by 0x4D1AF81: _HB_OPEN_Load_Device (harfbuzz-open.c:1318)
==6190== by 0x4D14D29: Load_Anchor (harfbuzz-gpos.c:639)
==6190== by 0x4D153AE: Load_MarkBasePos (harfbuzz-gpos.c:2040)
==6190== by 0x4D19875: _HB_GPOS_Load_SubTable (harfbuzz-gpos.c:5801)
==6190== by 0x4D1CA35: _HB_OPEN_Load_LookupList (harfbuzz-open.c:458)
==6190== by 0x4D1A93A: HB_Load_GPOS_Table (harfbuzz-gpos.c:141)
==6190== by 0x4D1F27C: HB_NewFace (harfbuzz-shaper.cpp:988)
==6190== by 0x4D24343: qHBNewFace(void*, HB_Error (*)(void*, unsigned int, unsigned char*, unsigned int*)) (qharfbuzz.cpp:154)
==6190== by 0x4478B06: QFreetypeFace::getFace(QFontEngine::FaceId const&) (qfontengine_ft.cpp:238)
==6190== by 0x4478FD9: QFontEngineFT::init(QFontEngine::FaceId, bool, QFontEngineFT::GlyphFormat) (qfontengine_ft.cpp:644)
==6190==
==6190==
==6190== 148 (128 direct, 20 indirect) bytes in 1 blocks are definitely lost in loss record 65 of 127
==6190== at 0x4026FDE: malloc (vg_replace_malloc.c:207)
==6190== by 0x4B379D6: (within /usr/lib/libfontconfig.so.1.3.0)
==6190== by 0x4B383C7: (within /usr/lib/libfontconfig.so.1.3.0)
==6190== by 0x4B384DE: (within /usr/lib/libfontconfig.so.1.3.0)
==6190== by 0x4B3DFBE: (within /usr/lib/libfontconfig.so.1.3.0)
==6190== by 0x5263EC3: (within /usr/lib/libexpat.so.1.5.2)
==6190== by 0x5264C10: (within /usr/lib/libexpat.so.1.5.2)
==6190== by 0x52665EE: (within /usr/lib/libexpat.so.1.5.2)
==6190== by 0x5266CE6: (within /usr/lib/libexpat.so.1.5.2)
==6190== by 0x525D68B: XML_ParseBuffer (in /usr/lib/libexpat.so.1.5.2)
==6190== by 0x4B3BEFD: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.3.0)
==6190== by 0x4B3C245: FcConfigParseAndLoad (in /usr/lib/libfontconfig.so.1.3.0)
==6190==
==6190==
==6190== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 66 of 127
==6190== at 0x4026FDE: malloc (vg_replace_malloc.c:207)
==6190== by 0x51A3548: nss_parse_service_list (nsswitch.c:547)
==6190== by 0x51A3E25: __nss_database_lookup (nsswitch.c:134)
==6190== by 0x803AF5B: ???
==6190== by 0x803BCBE: ???
==6190== by 0x5149811: getpwnam_r@@GLIBC_2.1.2 (getXXbyYY_r.c:253)
==6190== by 0x4F1FE71: (within /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4F21924: g_get_home_dir (in /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x7FFF524: ORBit_option_parse (in /usr/lib/libORBit-2.so.0.1.0)
==6190== by 0x800600F: CORBA_ORB_init (in /usr/lib/libORBit-2.so.0.1.0)
==6190== by 0x7FBF66E: gconf_orb_get (in /usr/lib/libgconf-2.so.4.1.5)
==6190== by 0x7FBF7FD: (within /usr/lib/libgconf-2.so.4.1.5)
==6190==
==6190==
==6190== 216 bytes in 1 blocks are definitely lost in loss record 75 of 127
==6190== at 0x4026FDE: malloc (vg_replace_malloc.c:207)
==6190== by 0x4BC2012: _XimOpenIM (in /usr/lib/libX11.so.6.2.0)
==6190== by 0x4BC1E4F: _XimRegisterIMInstantiateCallback (in /usr/lib/libX11.so.6.2.0)
==6190== by 0x4BA6037: XRegisterIMInstantiateCallback (in /usr/lib/libX11.so.6.2.0)
==6190== by 0x47B843D: QXIMInputContext::QXIMInputContext() (qximinputcontext_x11.cpp:370)
==6190== by 0x47B68C0: QInputContextFactory::create(QString const&, QObject*) (qinputcontextfactory.cpp:135)
==6190== by 0x419C997: QApplication::inputContext() const (qapplication.cpp:4929)
==6190== by 0x41DCCD4: QWidgetPrivate::inputContext() const (qwidget.cpp:271)
==6190== by 0x41E23AA: QWidget::inputContext() (qwidget.cpp:290)
==6190== by 0x419A044: QApplicationPrivate::setFocusWidget(QWidget*, Qt::FocusReason) (qapplication.cpp:2091)
==6190== by 0x41E691C: QWidget::setFocus(Qt::FocusReason) (qwidget.cpp:5747)
==6190== by 0x419EF58: QApplication::setActiveWindow(QWidget*) (qapplication.cpp:2442)
==6190==
==6190==
==6190== 1,084 bytes in 29 blocks are possibly lost in loss record 96 of 127
==6190== at 0x4025092: calloc (vg_replace_malloc.c:397)
==6190== by 0x4EF320B: g_malloc0 (in /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4ADB12B: (within /usr/lib/libgobject-2.0.so.0.2000.1)
==6190== by 0x4ADB1A5: (within /usr/lib/libgobject-2.0.so.0.2000.1)
==6190== by 0x4ADD7E7: g_type_init_with_debug_flags (in /usr/lib/libgobject-2.0.so.0.2000.1)
==6190== by 0x4ADD971: g_type_init (in /usr/lib/libgobject-2.0.so.0.2000.1)
==6190== by 0x453A8A9: QCleanlooksStylePrivate::lookupIconTheme() const (qcleanlooksstyle.cpp:4399)
==6190== by 0x453D903: QCleanlooksStyle::standardIconImplementation(QStyl e::StandardPixmap, QStyleOption const*, QWidget const*) const (qcleanlooksstyle.cpp:4431)
==6190== by 0x48463E7: QCleanlooksStyle::qt_metacall(QMetaObject::Call, int, void**) (moc_qcleanlooksstyle.cpp:72)
==6190== by 0x4DAC9A1: QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const (qmetaobject.cpp:1522)
==6190== by 0x4DACF8B: QMetaObject::invokeMethod(QObject*, char const*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) (qmetaobject.cpp:1114)
==6190== by 0x447A16F: QStyle::standardIcon(QStyle::StandardPixmap, QStyleOption const*, QWidget const*) const (qstyle.cpp:2261)
==6190==
==6190==
==6190== 4,288 bytes in 8 blocks are possibly lost in loss record 114 of 127
==6190== at 0x4024EFA: memalign (vg_replace_malloc.c:460)
==6190== by 0x4024FAE: posix_memalign (vg_replace_malloc.c:569)
==6190== by 0x4F08A02: (within /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4F0A1E2: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4EC389E: g_array_sized_new (in /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4EC39B6: g_array_new (in /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4F15A8B: g_static_private_set (in /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4ED340F: g_get_filename_charsets (in /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4ED3480: (within /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4F15D2C: g_thread_init_glib (in /usr/lib/libglib-2.0.so.0.2000.1)
==6190== by 0x4EA369C: g_thread_init (in /usr/lib/libgthread-2.0.so.0.2000.1)
==6190== by 0x4DD29A9: QEventDispatcherGlibPrivate::QEventDispatcherGlibP rivate(_GMainContext*) (qeventdispatcher_glib.cpp:231)
==6190==
==6190== LEAK SUMMARY:
==6190== definitely lost: 382 bytes in 4 blocks.
==6190== indirectly lost: 140 bytes in 11 blocks.
==6190== possibly lost: 5,372 bytes in 37 blocks.
==6190== still reachable: 241,002 bytes in 5,187 blocks.
==6190== suppressed: 0 bytes in 0 blocks.
==6190== Reachable blocks (those to which a pointer was found) are not shown.
==6190== To see them, rerun with: --leak-check=full --show-reachable=yes

bunjee
19th August 2009, 17:43
Thanks,

Valgrind is Linux only.

I'd like to track memory leak directly from my Qt C++ code.

Maybe I can achieve that by overloading new operator.

I'm surprised nobody did that before.