Preventing/handling space leaks

Iavor S. Diatchki diatchki at
Wed Dec 10 09:49:54 EST 2003


Henk-Jan van Tuyl wrote:

> I have spent most of the six years with my former employer coding in C 
> and some time in Java (and other languages) and had never any trouble 
> with space leaks; mainly because I strictly followed some rules for 
> Good Coding Practice (never use gotos, only one return statement per 
> function, catch exceptions as early
> as possible, keep variables as local as possible, always check the 
> number of free()s, etc. (etc. == etcetera == and so forth :-) ))
> So far I have seen only one rule for Good Coding Practice in Haskell: 
> Do Not Use n+k Patterns. I hope someone can give some directions, how 
> to avoid known pitfalls (especially Space Leaks).
not that i am a big fan of n+k patterns but why are they bad coding 
as for avoiding space leaks, it is conceptually easy -- make sure that 
things you thought are evaluated, really are.
use a profiler to confirm that what you established by looking at the 
code is correct.
the quiestions are not as easy if you are writing a library --
often there is a trade off between lazyness and space leaks.  
typically you can make your code strict, and then it will be less likely 
to leak,
but may surprise users with its behaviour, or one can make the code lazy,
but then is some situations it will leak. 
just my 2 stotinki.

| Iavor S. Diatchki, Ph.D. student               | 
| Department of Computer Science and Engineering |
| School of OGI at OHSU                          |
|               |

More information about the Haskell-Cafe mailing list