For my current program in Mathematica, sometimes I will encounter an error regarding \$IterationLimit and \$RecursionLimit. So I always set these two numbers to very large at the starting of every notebook. Till now, I didn't find any problem.
I want to understand what's the disadvantage of using a huge \$RecursionLimit or \$IterationLimit? By doing this way will I make the code slower or consume more memory?
For other languages, I heard this is related to the stack of evaluations. But I have no idea how memory is manipulated for Mathematica for this aspect.
Apparently, if there is no disadvantage Mathematica should always set these two numbers to Infinity.
$IterationLimit
and$RecursionLimit
in first place than worry about how to increase them? I do not think I've hitIterationLimit
myself, but did withRecursionLimit
number of times, and always this was due to a bug in my code. Without a limit, then Mathematica will most likely end up using all the memory it can or worst go into an infinite loop and you have to kill the process from outside. That is why they set this limit internally. $\endgroup$limit
suggests that this is a value that should never be reached inadvertently. That the user is nearing that limit is often, but not always, indicative of a looming crash. Could you please add an example to make a more concrete case for the counter argument? $\endgroup$LocalObject
, though, and avoid the risk. Thirdly, high recursion pushing large amounts of data onto a stack could result in swapping, which would waste my time, if refactoring the code could eliminate swapping. — Another point of view: a kernel crash could annoy a client. $\endgroup$