fix critical when closing a window with no other references