withWindow now correctly disposes of the created window