free memory when update