Freeing memory
Posted: Mon Aug 16, 2010 6:37 pm
Hey, is it best to free dynamic memory in a class's destructor or in a member function?
Example:
Does it not matter ( obviously other than the fact the member function will have to be called )? Does it depend on the situation? Should the cleanUp function be called the destructor? Thanks for any help in advance and I hope this isn't an absolute noob question.
Example:
Code: Select all
SomeClass::~SomeClass( void ) {
delete a;
delete [] b;
}
// or
void SomeClass::cleanUp( void ) {
delete a;
delete [] b;
}