Closing windows unregister properly (with test code).