freeing memory before dying