Why do we have stack overflows?

Adrian Hey ahey at iee.org
Thu May 3 12:40:24 EDT 2007

Duncan Coutts wrote:
> On Thu, 2007-05-03 at 16:24 +0100, Adrian Hey wrote:
>> Hello Folks,
>> Just wondering about this. Please understand I'm not asking why
>> programs use a lot of stack sometimes, but specifically why is
>> using a lot of stack (vs. using a lot of heap) generally regarded
>> as "bad". Or at least it seems that way given that ghc run time
>> makes distinction between the two and sets separate
>> limits for them (default max stack size being relatively small
>> whereas default max heap size in unlimited). So programs can
>> fail with a stack overflow despite having bucket loads of heap
>> available?
> Perhaps it's there to help people who write simple non-terminating
> recursion. They'll get an error message fairly soon rather than using
> all memory on the machine and invoking the wrath of the OOM killer.

Hmm, I still don't see why a "stack leak" should be treated differently
from "heap leak". They'll both kill your program in the end.

Adrian Hey

More information about the Glasgow-haskell-users mailing list