[Interest] Memory Leak when instantiating QWidget based windows

Edward Sutton edward.sutton at subsite.com
Thu Sep 8 15:13:23 CEST 2016


Hi Andy,

Could you please elaborate on step #3?

I cannot find a Memcheck option under Preferences > Debugger.

Thanks for the tips!

-Ed
Qt Creator 4.01 with Qt 5.6.1


On Sep 8, 2016, at 7:56 AM, Andy <asmaloney at gmail.com<mailto:asmaloney at gmail.com>> wrote:

Mike:

If you haven't already tried it, using Qt Creator in combination with valgrind works really well to track these kinds of things down.

The basics:

  1) install valgrind (I used homebrew)
  2) point Qt Creator at it in the prefs (Analyzer->Valgrind)
  3) Click the Debug tab, set the tool to Memcheck, and click the start button (little green arrow)

After it runs your application (slowly), it will spit out a bunch of info about memory leaks that make it pretty easy to track down the problems.




---
Andy Maloney  //  https://asmaloney.com<https://urldefense.proofpoint.com/v2/url?u=https-3A__asmaloney.com&d=DQMFaQ&c=G4BpsyPyB19LB50bn2swXw&r=cAG2c-SQES5P2qb8IW-uwnBOCX_f2qYJIlzenFnoHUc&m=c5VUb3aKymRQx0ih8A7yljotGOJbYdQ2iJ1PDgaS508&s=r8u8ZRFO-Qd4fneoIZohXBUjpcA_h7vjbk3y92UEclg&e=>
twitter ~ @asmaloney<https://urldefense.proofpoint.com/v2/url?u=https-3A__twitter.com_asmaloney&d=DQMFaQ&c=G4BpsyPyB19LB50bn2swXw&r=cAG2c-SQES5P2qb8IW-uwnBOCX_f2qYJIlzenFnoHUc&m=c5VUb3aKymRQx0ih8A7yljotGOJbYdQ2iJ1PDgaS508&s=o5ozT95AtJLPuZ0_E6csAPsjuGwFJwioJcJtEJxKwNk&e=>


On Thu, Sep 8, 2016 at 6:55 AM, Konstantin Shegunov <kshegunov at gmail.com<mailto:kshegunov at gmail.com>> wrote:

On Wed, Sep 7, 2016 at 11:23 PM, Mike Jackson <imikejackson at gmail.com<mailto:imikejackson at gmail.com>> wrote:
We monitor the memory use before and after the loop using OS X's Activity monitor. At the end of the loop there is more memory being used than before the loop, by about 2~3MB worth.

This isn't reliable. Consider the following C++ only code:

int main(int argc, char ** argv)

{

    struct X;

    X * x = nullptr;


    struct X {

        int data[1024];

    };


    for (qint32 i = 0; i < 100000; i++)  {

        x = new X[1024];

        delete x;

    }


    return 0;

}


In the KSysGuard (KDE's system monitor) I observe for the memory consumption: 12 908k, 23 048k shared before the loop and 12 944k, 25 112k shared after the loop. There isn't a leak here, yet there's a difference. The OS's heap manager may free the memory immediately, may cache it, or hold on to it. Ultimately it's out of your control, that's why you should use a code analyzer (like valgrind to track leaks).


Kind regards.

_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/interest<https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest&d=DQMFaQ&c=G4BpsyPyB19LB50bn2swXw&r=cAG2c-SQES5P2qb8IW-uwnBOCX_f2qYJIlzenFnoHUc&m=c5VUb3aKymRQx0ih8A7yljotGOJbYdQ2iJ1PDgaS508&s=LqLQXbnpsD6fQrnO0sB2UvftUi_snCYjEZU1tDFt7So&e=>


_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest&d=DQICAg&c=G4BpsyPyB19LB50bn2swXw&r=cAG2c-SQES5P2qb8IW-uwnBOCX_f2qYJIlzenFnoHUc&m=c5VUb3aKymRQx0ih8A7yljotGOJbYdQ2iJ1PDgaS508&s=LqLQXbnpsD6fQrnO0sB2UvftUi_snCYjEZU1tDFt7So&e=

This email and any files transmitted with it from The Charles Machine Works, Inc. are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the sender. Our company accepts no liability for the contents of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160908/c08e5d85/attachment.html>


More information about the Interest mailing list