fix a memory leak when opening a new window