Using Recursion in C#

前端 未结 10 658
我寻月下人不归
我寻月下人不归 2020-12-14 20:19

Are there any general rules when using recursion on how to avoid stackoverflows?

10条回答
  •  一整个雨季
    2020-12-14 20:39

    If you're finding yourself generating that many stack frames, you might want to consider unrolling your recursion into a loop.

    Especially if you are doing multiple levels of recursion (A->B->C->A->B...) you might find that you can extract one of those levels into a loop and save yourself some memory.

提交回复
热议问题