handle the memory of view switch