Results 1 to 19 of 19

Thread: memory leak

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: memory leak

    I think i get the big problem, try to check please:

    Qt Code:
    1. ==26261== 4136 (2204 direct, 1932 indirect) bytes in 1 blocks are definitely lost in loss record 124 of 139
    2. ==26261== at 0x1B90939A: operator new(unsigned) (vg_replace_malloc.c:132)
    3. ==26261== by 0x809FC82: main (trm.cpp:62)
    To copy to clipboard, switch view to plain text mode 

    trm.cpp
    Qt Code:
    1. int main ( int argc, char *argv[] )
    2. {
    3. QApplication app ( argc, argv );
    4. ...
    5. ...
    6. // creating splash object
    7. QPixmap pixmap ( ":/trm/images/SplashScreen.png" );
    8. QSplashScreen * splash = new QSplashScreen ( pixmap );
    9. splash->show();
    10. splash->showMessage ( QObject::tr ("Loading settings..." ) , Qt::AlignRight | Qt::AlignBottom , Qt::black );
    11.  
    12. // creating main window
    13. twmMainWindow *mytwmMainWindow = new twmMainWindow(); // <-- trm.cpp:62
    14. mytwmMainWindow->show();
    15.  
    16. // closing and destroing splash screen
    17. splash->finish ( mytwmMainWindow );
    18. delete splash;
    19.  
    20. // run the main loop!
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    Where hould i delete the statement in trm.cpp:62?
    I have to put it in my trm.h and in trm.cpp i have just to do
    mytwmMainWindow = new twmMainWindow();
    and destroy it at the end?
    Thx

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: memory leak

    Just allocate it on the stack:
    Qt Code:
    1. twmMainWindow mytwmMainWindow(); // <-- trm.cpp:62
    2. mytwmMainWindow.show();
    To copy to clipboard, switch view to plain text mode 
    or alternatively set Qt::WA_CloseOnDelete attribute:
    Qt Code:
    1. twmMainWindow *mytwmMainWindow = new twmMainWindow(); // <-- trm.cpp:62
    2. mytwmMainWindow->setAttribute(Qt::WA_DeleteOnClose);
    3. mytwmMainWindow->show();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: memory leak

    Quote Originally Posted by jpn View Post
    Just allocate it on the stack:
    Qt Code:
    1. twmMainWindow mytwmMainWindow(); // <-- trm.cpp:62
    2. mytwmMainWindow.show();
    To copy to clipboard, switch view to plain text mode 
    In this way i got this error
    Qt Code:
    1. error: request for member ‘show’ in ‘mytwmMainWindow’, which is of non-class type ‘twmMainWindow (
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by jpn View Post
    Just allocate it on the stack:
    or alternatively set Qt::WA_CloseOnDelete attribute:
    Qt Code:
    1. twmMainWindow *mytwmMainWindow = new twmMainWindow(); // <-- trm.cpp:62
    2. mytwmMainWindow->setAttribute(Qt::WA_DeleteOnClose);
    3. mytwmMainWindow->show();
    To copy to clipboard, switch view to plain text mode 
    In this way i'm able to run my app but nothing change...
    thx

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: memory leak

    Quote Originally Posted by mattia View Post
    In this way i got this error
    Qt Code:
    1. error: request for member ‘show’ in ‘mytwmMainWindow’, which is of non-class type ‘twmMainWindow (
    To copy to clipboard, switch view to plain text mode 
    I didn't notice that class and variable names were exactly the same. So rename the variable name to be something different than what the class name is. For example:
    Qt Code:
    1. twmMainWindow mainWindow; // <-- trm.cpp:62
    2. mainWindow.show();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    mattia (16th January 2008)

  6. #5
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: memory leak

    thanks so much! I learned a lot of cool stuff about memory leak and i fixed my problem.

Similar Threads

  1. Memory leak detection
    By Sid in forum Qt Programming
    Replies: 8
    Last Post: 4th May 2011, 22:38
  2. Memory leak?
    By Enygma in forum Qt Programming
    Replies: 10
    Last Post: 4th September 2007, 16:24
  3. QPixMap and Memory leak
    By Krish_ng in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 14:18
  4. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42
  5. Qt 4.1 Memory Leak
    By blackliteon in forum Qt Programming
    Replies: 14
    Last Post: 10th February 2006, 12:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.