When implementing reference counting in objects the "release and possibly delete object" primitive is usually implemented like this:
void CObject::Release()
{
--referenceCount;
if( referenceCount == 0 ) {
delete this;
}
}
First of all, delete this
looks scary. But since the member function returns immediately and doesn't try to access any member variables the stuff still works allright. At least that's how it is explained usually. The member function might even call some global function to write to a log that it deleted the object.
Does the C++ standard guarantee that a member function can call delete this
and then do anything that will not require access to member variables and calling member functions and this will be defined normal behaviour?