Finally tracked down the bug, it was with getLevel order having two get
left nodes instead of left and right. Now the memory leak is gone and
the program works correctly.