Fix memory leak moving a document into its view