Why does a recursive call cause StackOverflow at different stack depths?
I was trying to figure out hands-on how tail calls are handled by the C# compiler. (Answer: They're not. But the 64bit JIT(s) WILL do TCE (tail call elimination). Restrictions apply .) So I wrote a small test using a recursive call that prints how many times it gets called before the StackOverflowException kills the process. class Program { static void Main(string[] args) { Rec(); } static int sz = 0; static Random r = new Random(); static void Rec() { sz++; //uncomment for faster, more imprecise runs //if (sz % 100 == 0) { //some code to keep this method from being inlined var zz = r.Next();