Properly clean up used memory when opening multiple documents in the GUI.