Why does this recursive method cause a Stack Overflow error when it has no variables?

The stack frame does not just contain parameters, it also contains a return address, so that the processor knows where to go back to.

Furthermore, the hidden this pointer is also a parameter. To remove that you would need a static function.

There is also the ebp or other stack-frame pointer, which can be pushed onto the stack for each call, depending on the exact calling convention.

So whatever you do, you will definitely get a stack overflow at some point, unless the compiler decides to perform tail-recursion.

Read more here: Source link