No it is not needed that these objects be on heap, it's just that it is a small test case so I made different objects so that whoever reads this case can make a picture of the tree in his head while going through it and understand which function is doing what.