Logging and cleanup for HeapSort.