The destroy procedure in the Core widget deals with the unregistration, and that procedure is available by reference. The code resets to NULL these fields in the core structure, the form of which is public. The problem of avoiding having the window destroyed is solved by then resetting it to None. Well, Shell widgets handle their own window destruction, so resubclassing the widget from Shell nicely solves this problem. The C source code shows the implementation, which winds up being relatively simple.
Full sources are also available.
Unfortunately, not all systems are using the latest and greatest code, and problems in programming still need to be solved.