Free memory after closing the preview and the setting windows