Detect Class being set to NIL

With a graphics printer object… it ejects the last page when you set it to NIL (G=NIL)

Is there a way to detect this type of operation for user defined custom classes (OR is that the PURPOSE of DESTRUCTOR)?

When the app sets the class object to NIL I need it to perform a few last operations before it truly “dies”

That’s what a destructor is for.