add memory free functions

need to make sure all used memory is freed at the end of
mouse simulation.