Your Objects free() method is called before Max quits. Either do there what needs to be done or in your notify() method which for example gets called before the parent patcher window closes, which also happens before Max quits.
Have a look at the notify method in the scripto example, you have to check the msg argument and the sender.
if(msg == gensym("free"))
if(sender == x->myParentPatcherWindow)
do what needs to be done...
The problem with these methods is, that they also get called when Max doesn't quit.
The reason i need this is because i have an global context variable that needs to be shared amongst instances of my object.
The context gets initialized in the class_new method.
I thought maybe there's also a customizable class_free method, where I could close the context.
So I guess I'll have to count the number of object instances, close the context when there are no more instances and reinitalize the context in the object's new method.
In ext_proto.h there's a quittask_install() function prototyped.
That allows you to register a method that will be called ONLY when Max quits.
It might provide a better alternative to counting the number of object instances.