devxlogo

Verifying a Destructor’s Invocation

Verifying a Destructor’s Invocation

Conceptually, destructors of global objects are called after main() has exited. For this reason, many debugging and memory checking tools are confused and report phantom memory leaks or warn about destructors that allegedly don’t execute. In most cases, you can ignore these false alarms. For instance, when they are reported on the iostream objects. However, if you want to verify that destructors of user-defined global objects are called, you can create a file in the destructor and examine whether it was created after the program terminates. Alternatively, you can emit a beep from the destructor.

devx-admin

Share the Post: