Index: generic/nsf.c =================================================================== diff -u -N -rb36a57bbc5ab0ff8361293a4e73c7ac5b4da4b2d -r9395752d7b314f92d86b2fabab1070aa93bbfbc8 --- generic/nsf.c (.../nsf.c) (revision b36a57bbc5ab0ff8361293a4e73c7ac5b4da4b2d) +++ generic/nsf.c (.../nsf.c) (revision 9395752d7b314f92d86b2fabab1070aa93bbfbc8) @@ -25070,7 +25070,7 @@ } #endif - fprintf(stderr, "+++ call tcl-defined exit handler (%lx)\n", pthread_self()); + /*fprintf(stderr, "+++ call tcl-defined exit handler (%x)\n", PTR2INT(pthread_self()));*/ /* * Evaluate user-defined exit handler. @@ -31466,7 +31466,19 @@ continue; } - /*fprintf(stderr, "cl key = %s %p\n", ClassName(cl), cl); */ + /*fprintf(stderr, "### cl key = %s %p\n", ClassName(cl), cl); */ + + /* + * Remove manually mixinRegObjs to achieve correct deletion + * order. Otherwise, refcount checking for NsfObjects complains during + * shutdown (and dangling references would be a consequence). + */ + if (cl->opt != NULL && cl->opt->mixinRegObjs != NULL) { + NsfMixinregInvalidate(interp, cl->opt->mixinRegObjs); + DECR_REF_COUNT2("mixinRegObjs", cl->opt->mixinRegObjs); + cl->opt->mixinRegObjs = NULL; + } + if (!ObjectHasChildren((NsfObject *)cl) && !ClassHasInstances(cl) && !ClassHasSubclasses(cl)