Widget destruction, and resource management in general, is one of the trickier things to get right in a Tk widget implementation. There are more bugs per square foot in this area of the core than anywhere else. What I'm looking for is a recipe for how to properly handle the widget lifecycle. (When I asked about this on the chatroom, [DGP] said: "typically there's a "deleted" flag in the struct, and lots of Tcl_Preserve()'s around." But there are apparently no formalized guidelines anywhere...) There are several cases to handle: * The widget instance command is deleted, in which case the command deletion proc is responsible for calling Tk_DestroyWindow (this falls through to the next case) * Someone calls Tk_DestroyWindow() on the widget or one of its ancestors, in which case the widget will receive precisely one event. In this case the event handler is responsible for deleting the widget command. * Some other process calls XDestroyWindow, in which case the widget will receive precisely one event. * A script calls [[exit]] * Someone deletes the Tcl_Interp in which the widget was created There are probably more .... ''more to come ... '' ---- [[ [Category Internals] ]]