release memory on stateExit