Yes, ns_atclose might solve the 'when' issue, but not the 'what', which is unsolvable in a general way - for every custom library something different needs to be done. E.g. when using the tcl http package and using ::http::config -useragent to set the user agent variable, there seems to be no other way to reset it to the default value than manually. That's simply something to be aware of when using package require.