c++visual-studioqtmemory-leaksvisual-leak-detector

Visual Leak Detector reports qt library leaks


I created a Qt 4.7.4 program and then included the vld library to detect memory leaks. The result is I get too many leaks that the majority are Qt library leaks, which is a strange. Has anyone encountered this problem before?

The memory_leak_report.txt is like this:

Visual Leak Detector Version 2.5.1 installed.
    Outputting the report to C:\Users\kelgharb\Documents\Visual Studio 2010\Projects\Entreprise\EntrepriseCreator\memory_leak_report.txt WARNING: Visual Leak Detector detected memory leaks!
---------- Block 25 at 0x00E07E58: 20 bytes ----------   Leak Hash: 0x5688712A, Count: 1, Total 20 bytes   Call Stack (TID 1348):
    MSVCR100D.dll!operator new()
    c:\users\kelgharb\documents\visual studio 2010\projects\entreprise\entreprisecreator\generatedfiles\ui_createentreprise.h (50): EntrepriseCreator.exe!Ui_CreateEntrepriseClass::setupUi() + 0x7 bytes
    c:\users\kelgharb\documents\visual studio 2010\projects\entreprise\entreprisecreator\createentreprise.cpp (10): EntrepriseCreator.exe!CreateEntreprise::CreateEntreprise()
    c:\users\kelgharb\documents\visual studio 2010\projects\entreprise\entreprisecreator\entreprisecreator.cpp (45): EntrepriseCreator.exe!EntrepriseCreator::onTrigger_createEntreprise()
+ 0x31 bytes
    c:\users\kelgharb\documents\visual studio 2010\projects\entreprise\entreprisecreator\generatedfiles\debug\moc_entreprisecreator.cpp (82): EntrepriseCreator.exe!EntrepriseCreator::qt_metacall() + 0x8 bytes
    c:\qt\4.7.4\src\corelib\kernel\qmetaobject.cpp (238): QtCored4.dll!QMetaObject::metacall()
    c:\qt\4.7.4\src\corelib\kernel\qobject.cpp (3278): QtCored4.dll!QMetaObject::activate() + 0x27 bytes
    c:\qt\4.7.4\src\gui\tmp\moc\debug_shared\moc_qaction.cpp (263): QtGuid4.dll!QAction::triggered() + 0x15 bytes
    c:\qt\4.7.4\src\gui\kernel\qaction.cpp (1259): QtGuid4.dll!QAction::activate()
    c:\qt\4.7.4\src\gui\widgets\qmenu.cpp (1007): QtGuid4.dll!QMenuPrivate::activateCausedStack()
    c:\qt\4.7.4\src\gui\widgets\qmenu.cpp (1100): QtGuid4.dll!QMenuPrivate::activateAction()
    c:\qt\4.7.4\src\gui\widgets\qmenu.cpp (2297): QtGuid4.dll!QMenu::mouseReleaseEvent()
    c:\qt\4.7.4\src\gui\kernel\qwidget.cpp (8296): QtGuid4.dll!QWidget::event()
    c:\qt\4.7.4\src\gui\widgets\qmenu.cpp (2406): QtGuid4.dll!QMenu::event()
    c:\qt\4.7.4\src\gui\kernel\qapplication.cpp (4481): QtGuid4.dll!QApplicationPrivate::notify_helper() + 0x11 bytes
    c:\qt\4.7.4\src\gui\kernel\qapplication.cpp (4042): QtGuid4.dll!QApplication::notify() + 0x2F bytes
    c:\qt\4.7.4\src\corelib\kernel\qcoreapplication.cpp (787): QtCored4.dll!QCoreApplication::notifyInternal() + 0x15 bytes
    c:\qt\4.7.4\src\corelib\kernel\qcoreapplication.h (218): QtCored4.dll!QCoreApplication::sendSpontaneousEvent() + 0x38 bytes
    c:\qt\4.7.4\src\gui\kernel\qapplication.cpp (3139): QtGuid4.dll!QApplicationPrivate::sendMouseEvent() + 0xE bytes
    c:\qt\4.7.4\src\gui\kernel\qapplication_win.cpp (3234): QtGuid4.dll!QETWidget::translateMouseEvent() + 0x2A bytes
    c:\qt\4.7.4\src\gui\kernel\qapplication_win.cpp (1659): QtGuid4.dll!QtWndProc() + 0xC bytes
    USER32.dll!gapfnScSendMessage() + 0x332 bytes
    USER32.dll!GetThreadDesktop() + 0xD7 bytes
    USER32.dll!CharPrevW() + 0x138 bytes
    USER32.dll!DispatchMessageW() + 0xF bytes
    c:\qt\4.7.4\src\corelib\kernel\qeventdispatcher_win.cpp (810): QtCored4.dll!QEventDispatcherWin32::processEvents()
    c:\qt\4.7.4\src\gui\kernel\qapplication_win.cpp (1170): QtGuid4.dll!QGuiEventDispatcherWin32::processEvents() + 0x15 bytes
    c:\qt\4.7.4\src\corelib\kernel\qeventloop.cpp (150): QtCored4.dll!QEventLoop::processEvents()
    c:\qt\4.7.4\src\corelib\kernel\qeventloop.cpp (201): QtCored4.dll!QEventLoop::exec() + 0x2D bytes
    c:\qt\4.7.4\src\corelib\kernel\qcoreapplication.cpp (1064): QtCored4.dll!QCoreApplication::exec() + 0x15 bytes
    c:\qt\4.7.4\src\gui\kernel\qapplication.cpp (3756): QtGuid4.dll!QApplication::exec()
    c:\users\kelgharb\documents\visual studio 2010\projects\entreprise\entreprisecreator\main.cpp (12): EntrepriseCreator.exe!main() + 0x6 bytes
    c:\qt\4.7.4\src\winmain\qtmain_win.cpp (131): EntrepriseCreator.exe!WinMain() + 0x12 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (547): EntrepriseCreator.exe!__tmainCRTStartup() + 0x2C bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (371): EntrepriseCreator.exe!WinMainCRTStartup()
    kernel32.dll!BaseThreadInitThunk() + 0x12 bytes
    ntdll.dll!RtlInitializeExceptionChain() + 0x63 bytes
    ntdll.dll!RtlInitializeExceptionChain() + 0x36 bytes   Data:
    D4 50 01 01    18 0A 92 02    AC 50 01 01    00 00 CD CD     .P...... .P......
    D0 0A 92 02                                                  ........ ........
---------- Block 22 at 0x02892950: 52 bytes ----------   Leak Hash: 0x04BB07FE, Count: 1, Total 52 bytes   Call Stack (TID 1348):
    MSVCR100D.dll!operator new()
    c:\users\kelgharb\documents\visual studio 2010\projects\entreprise\entreprisecreator\entreprisecreator.cpp (45): EntrepriseCreator.exe!EntrepriseCreator::onTrigger_createEntreprise()
+ 0x7 bytes
    c:\users\kelgharb\documents\visual studio 2010\projects\entreprise\entreprisecreator\generatedfiles\debug\moc_entreprisecreator.cpp (82): EntrepriseCreator.exe!EntrepriseCreator::qt_metacall() + 0x8 bytes
    c:\qt\4.7.4\src\corelib\kernel\qmetaobject.cpp (238): QtCored4.dll!QMetaObject::metacall()
    c:\qt\4.7.4\src\corelib\kernel\qobject.cpp (3278): QtCored4.dll!QMetaObject::activate() + 0x27 bytes
    c:\qt\4.7.4\src\gui\tmp\moc\debug_shared\moc_qaction.cpp (263): QtGuid4.dll!QAction::triggered() + 0x15 bytes
    c:\qt\4.7.4\src\gui\kernel\qaction.cpp (1259): QtGuid4.dll!QAction::activate()
    c:\qt\4.7.4\src\gui\widgets\qmenu.cpp (1007): QtGuid4.dll!QMenuPrivate::activateCausedStack()
    c:\qt\4.7.4\src\gui\widgets\qmenu.cpp (1100): QtGuid4.dll!QMenuPrivate::activateAction()
    c:\qt\4.7.4\src\gui\widgets\qmenu.cpp (2297): QtGuid4.dll!QMenu::mouseReleaseEvent()
    c:\qt\4.7.4\src\gui\kernel\qwidget.cpp (8296): QtGuid4.dll!QWidget::event()
    c:\qt\4.7.4\src\gui\widgets\qmenu.cpp (2406): QtGuid4.dll!QMenu::event()
    c:\qt\4.7.4\src\gui\kernel\qapplication.cpp (4481): QtGuid4.dll!QApplicationPrivate::notify_helper() + 0x11 bytes
    c:\qt\4.7.4\src\gui\kernel\qapplication.cpp (4042): QtGuid4.dll!QApplication::notify() + 0x2F bytes
    c:\qt\4.7.4\src\corelib\kernel\qcoreapplication.cpp (787): QtCored4.dll!QCoreApplication::notifyInternal() + 0x15 bytes
    c:\qt\4.7.4\src\corelib\kernel\qcoreapplication.h (218): QtCored4.dll!QCoreApplication::sendSpontaneousEvent() + 0x38 bytes
    c:\qt\4.7.4\src\gui\kernel\qapplication.cpp (3139): QtGuid4.dll!QApplicationPrivate::sendMouseEvent() + 0xE bytes
    c:\qt\4.7.4\src\gui\kernel\qapplication_win.cpp (3234): QtGuid4.dll!QETWidget::translateMouseEvent() + 0x2A bytes
    c:\qt\4.7.4\src\gui\kernel\qapplication_win.cpp (1659): QtGuid4.dll!QtWndProc() + 0xC bytes
    USER32.dll!gapfnScSendMessage() + 0x332 bytes

Solution

  • The memory leaks associated to Qt are due to the QDialogs, I was missing a line setAttribute(Qt::WA_DeleteOnClose),each time I created a new QDialog object:

    void EntrepriseCreator::onTrigger_createEntreprise()
    {
        CreateEntreprise* entreprise = new CreateEntreprise();
        entreprise->setAttribute(Qt::WA_DeleteOnClose);
        QObject::connect(entreprise, SIGNAL(disable_actionEntreprise(bool)), this, SLOT(disable_actionEntreprise(bool)));
        entreprise->exec();
    }