add dispose function on Window and call this function when window has been closed.