Results 1 to 5 of 5

Thread: 300KB of RAM lost after New and Delete

  1. #1
    Join Date
    May 2009
    Qt products
    Qt4 Qt/Embedded

    Unhappy 300KB of RAM lost after New and Delete

    After a New and a delete of a QDialog I lost 300KB of RAM. The problem become worst while more dialogs I use.

    I check the memory consumption starting my app in background and calling the command "free". At the begining after create and show the dialog the empty dialog consumes 1MB, after delete this object it leaves 300KB occupied.
    How can I release that memory?

    Qt Code:
    1. TErrorDialog *PantallaError;
    2. PantallaError = new TErrorDialog /*Form*/;
    3. PantallaError->show();
    To copy to clipboard, switch view to plain text mode 

    Here it consumes 1MB, checked with comand "free"

    Qt Code:
    1. PantallaError->hide();
    2. PantallaError->deleteLater(); // same as delete PantallaError
    3. PantallaError=NULL;
    To copy to clipboard, switch view to plain text mode 

    Here it leaves 300KB occupied.

    Just when I finish the application the memory is released.

  2. #2
    Join Date
    Jul 2009
    Thanked 6 Times in 6 Posts

    Default Re: 300KB of RAM lost after New and Delete

    I bet that the problem is in your TErrorDialog.
    You, maybe, are creating objects or widgets without parent... and you are not deleting them in the destructor.

  3. #3
    Join Date
    Sep 2009
    Thanked 348 Times in 333 Posts
    Qt products

    Default Re: 300KB of RAM lost after New and Delete

    You do realise that delete doesn't necessarily release all memory to the system at the exact moment that you call delete? You can check this by checking your memory using 'free' as you do, and then call new again, and you'll find the memory requirement doesn't increase as it's reusing memory from last time.

    You need to monitor your application memory use per-process, not by using a global tool such as 'free'.

  4. #4
    Join Date
    Apr 2010
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4

    Default Re: 300KB of RAM lost after New and Delete

    Squidge is correct; system-level tools are generally poor at accurately reporting memory usage.

    If you're concerned about memory leaks, you'd be much better off using a run-time analysis tool like valgrind to check actual allocation/deallocation during execution.

  5. #5
    Join Date
    Mar 2009
    Brisbane, Australia
    Thanked 1,587 Times in 1,516 Posts
    Qt products
    Qt4 Qt5
    Unix/X11 Windows
    Wiki edits

    Default Re: 300KB of RAM lost after New and Delete

    If TErrorDialog causes a plugin or other dynamic library to load, e.g. a JPEG handler or SQL driver, then this memory is lost to the system and will not be freed until the plugin is unloaded when the QApplication exits (assuming the shared library is not now being used by another process). Even a perfectly coded TErrorDialog may display this behaviour.

    As others have pointed out, there are tools for finding actual memory leaks.

Similar Threads

  1. Lost events.
    By chris_helloworld in forum Qt Programming
    Replies: 5
    Last Post: 15th September 2010, 14:36
  2. Hightlight not lost
    By wirasto in forum Qt Programming
    Replies: 0
    Last Post: 5th August 2010, 13:16
  3. Replies: 4
    Last Post: 19th February 2009, 11:10
  4. lost signals ?
    By deepinlife in forum Qt Programming
    Replies: 3
    Last Post: 17th June 2008, 10:11
  5. Lost widget
    By anli in forum Qt Programming
    Replies: 6
    Last Post: 29th July 2006, 19:02

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.