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?
Code:
TErrorDialog *PantallaError;
PantallaError = new TErrorDialog /*Form*/;
PantallaError->show();
Here it consumes 1MB, checked with comand "free"
Code:
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.
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.
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'.
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.
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.