PDA

View Full Version : 300KB of RAM lost after New and Delete



masterbraind
30th December 2010, 16:34
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?



TErrorDialog *PantallaError;
PantallaError = new TErrorDialog /*Form*/;
PantallaError->show();


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



PantallaError->hide();
PantallaError->deleteLater(); // same as delete PantallaError
PantallaError=NULL;


Here it leaves 300KB occupied.

Just when I finish the application the memory is released.

javimoya
30th December 2010, 17:16
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.

squidge
30th December 2010, 18:25
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'.

SixDegrees
30th December 2010, 19:00
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.

ChrisW67
30th December 2010, 19:26
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.