free memory before exiting