fix a memory leak bug when the app exits