Fixed cleanup of memory used up on heap