Revision as of 09:25, 20 July 2012 by
From Nokia Developer Wiki
Created:(20 Mar 2007)
Last edited:(20 Jul 2012)
Destructor usually deletes any extra resources allocated by the object.
Note, in Symbian C++:
- Destructor can NOT be allowed to leave! A leave from a destructor may cause the program to terminate abruptly. In S60 3rd edition and later releases a leave is an exception and there can be only one active exception at a time. The destructor may have been called as a part of a routine to handle an exception (leave) and raising another exception will cause the program to be terminated.
- Always delete objects your class owns, from the class destructor.
- Don’t delete objects that you don’t own (those that you merely use).
- Don’t allocate twice (this will cause a memory leak).
- Don’t delete twice (this will corrupt the heap).
- When you delete outside of the destructor, immediately set the pointer to zero.
- When you are reallocating, you must use the sequence ‘delete, set pointer to zero, allocate’, just in case the allocation fails.
See also delete.