I'm using a static binbuf, into which I have patchers save themselves. I use a static t_patcher to check if I'm in the same parent patcher as the last time any instance of my object saved a binbuf, and just use the cached static binbuf if so.
static t_object *obj_bb = NULL; // the binbuf
static t_patcher *obj_pp = NULL; // the patcher
if(obj_bb == NULL) obj_bb = binbuf_new(); // init the binbuf
if(obj_pp != pp) // pp is object instance parent patcher
binbuf_set(obj_bb, 0, 0, NULL); // nuke the old binbuf
mess1((Object *)pp, gensym("save"), obj_bb); // save into it
obj_pp = pp; // remember the new current parent patcher
This cuts down my init time considerably where a parent patcher contains lots of patchers containing my object - I save the parent patcher to binbuf once.
Should I free the static binbuf at quit? If so, how? Is this a suitable job for a quit task - which would presumably need to check the binbuf is not already freed by an earlier object quit task?