[Haskell-cafe] Garbage collection as a dual of laziness?
greenrd at greenrd.org
Sun Nov 23 05:18:48 EST 2008
It occurs to me that garbage collection can be seen as some kind of
dual of laziness. Laziness means deferring the creation of values until
later in the future (or even never). Garbage collection means eagerly
destroying data created in the past, and reclaiming the memory used by
it, before some other event which would do so (in most
garbage-collected languages, I think process destruction is the only
other thing that frees memory, leaving aside foreign functions).
If you don't have enough laziness (e.g. because of strict pattern
matching on tuples) your program might do unnecesssary work (time
wastage); if you don't have enough garbage collection (e.g. because a
value will never be accessed again but is still referred to from
something live), your program might leak memory (space wastage).
Of course, space wastage can lead to time wastage, and vice-versa.
Can this intuition be made any more formal? Is it merely of
pedagogical use, or does anything interesting follow from it?
More information about the Haskell-Cafe