Release memory when closing a map.