fixed heap-destruction issue with the array based implementation.