Are there any general rules when using recursion on how to avoid stackoverflows?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
How many times you will be able to recurse will depend on:
Guidlocal variables will be take more stack than a method which doesn’t have any local variables, for example)How to avoid stack overflows? Don’t recurse too far 🙂 If you can’t be reasonably sure that your recursion will terminate without going very far (I’d be worried at ‘more than 10’ although that’s very safe) then rewrite it to avoid recursion.