java.lang.StackOverflowError due to recursion

前端 未结 10 2259
南方客
南方客 2020-12-03 05:59

My problem is that I usually get a java.lang.StackOverflowError when I use recursion. My question is - why does recursion cause stackoverflow so much more than loops do, and

10条回答
  •  不思量自难忘°
    2020-12-03 06:22

    Every time you call a method, you consume a "frame" from the stack, this frame is not released until the method returns, it doesn't happen the same with loops.

提交回复
热议问题