Hello All.
A few weeks ago I threw out my C++ IDE's (KDevelop and MSVC++) and started using qmake with my own elementary project files so that I could better understand the build process. The only thing I miss about the IDE's is the facility which spots memory leaks.
I am using Qt and have been writing release versions. Inevitably, I have had a few crashes due to bad memory access attempts, but I have been able to easily fix these. However, I am not sure whether my programs are actually leaving memory leaks.
I know how to use 'new' and 'delete', but I am still working blind. I have a couple of questions...
----------------------------------------------
(1)
I currently write the destructors of any objects that I instantiate with 'new' as follows...
1 2 3 4 5 6 7
|
AClass::~AClass()
{
if( DeleteFlag )
{
delete this;
}
}
|
...where DeleteFlag is a bool that is initialised to 1 when the object is created. If the object needs to be deleted before the application closes down, I set DeleteFlag to zero, and I also set the pointer to zero.
----------------------------------------------
(2)
If the application process crashes, what happens to the borrowed memory?
(a) Does the OS call the destructor to reclaim the memory?
(b) Will the OS clean up without calling the destructor?
(c) Other...what?
----------------------------------------------
(3)
Is there an OS facility (perhaps in control panel somewhere) which will tell me whether there are any memory leaks?
----------------------------------------------
(4)
If you think I am doing things wrong, or you have a better 'failsafe' way of ensuring that my programs do not leave memory leaks, can you please let me know?
----------------------------------------------
Thanks very much all,
Dave