How can I determine if a C++ object has been deallocated?
c++
Solution
You can't easily tell just by looking at the memory location if the object is still allocated or not. There might be some black magic tricks to do that, but a much cleaner way would be to build a call-back mechanism into the object's destructor.
Problem
I have a previous question that was answered in which I describe difficulties catching an exception when I try to access an object that has been deallocated by a third-party function. The function sometimes does and sometimes doesn't deallocate the object. In order to avoid having to use a try/catch block to catch the SEH Exception as described in the previous question, I need to be able to tell whether the object has been deallocated or not. How can I determine if a C++ object has been deallocated or is still a valid pointer?