title: How to predict the maximum call depth of a recursive method?
body: <p>For the purposes of estimating the maximum call depth a recursive method may achieve with a given amount of memory, what is the (approximate) formula for calculating the memory used before a stack overflow error is likely to occur?</p>
  <h3>Edit:</h3>
  <p>Many have responded with &quot;it depends&quot;, which is reasonable, so let's remove some of the variables by using a trivial but concrete example:</p>
  <pre><code>public static int sumOneToN(int n) {
      return n &lt; 2 ? 1 : n + sumOneToN(n - 1);
  }
  </code></pre>
  <p>It is easy to show that running this in my Eclipse IDE explodes for <code>n</code> just under 1000 (surprisingly low to me).
  Could this call depth limit have been estimated without executing it?</p>
  <p>Edit: I can't help thinking that Eclipse has a fixed max call depth of 1000, because I got to <code>998</code>, but there's one for the main, and one for the initial call to the method, making <code>1000</code> in all. This is &quot;too round&quot; a number IMHO to be a coincidence. I'll investigate further. I have just Dux overhead the -Xss vm parameter; it's the maximum stack size, so Eclipse runner must have <code>-Xss1000</code> set somewhere</p>