Fix memory leak, close window