From: Tim Bates Date: 2005-03-19T09:29:55+09:00 Subject: Re: Maximum stack depth Csaba Henk wrote: > In my ruby installations under gentoo, there is no "stack level too > deep", ruby just eats up all memory and then the OS gracefully kills > it (it happens when I don't link it against pthread). I get the same thing (also on Gentoo), except with 1GB of RAM and 2GB of swap my system slows to a crawl long before the operating system kills it and my patience runs out. It can take some minutes to kill the program once I realise this is happening - which is generally when my swap space usage goes above 0%. I think I might actually prefer a stack level too deep error. Usually by the time my system starts swapping, the stack is over 200,000 levels deep. > It seems that function data is stored on the heap. Is it possible? Under > what circumstances can this phenomenon -- ie., that ruby doesn't runs > out of stack upon a deep recursion -- occur (OS, kernel (OS, compilation > options, compilation options, ...) ? After a bit of research, I've discovered that Gentoo by default doesn't have a stack size limit. Watch: (using the bash builtin `ulimit`) $ ulimit -a stack size (kbytes, -s) unlimited $ ulimit -s 1024 $ ruby -e 'def t(i) t(i+1) end;t 0' -e:1:in `t': stack level too deep (SystemStackError) from -e:1:in `t' from -e:1:in `t' from -e:1:in `t' from -e:1:in `t' from -e:1:in `t' from -e:1:in `t' from -e:1:in `t' from -e:1:in `t' ... 401 levels... from -e:1:in `t' from -e:1:in `t' from -e:1:in `t' from -e:1 Tim. -- Tim Bates tim@bates.id.au