method to free off-heap memory