[Haskell-cafe] Space leak with unsafePerformIO

Yitzchak Gale gale at sefer.org
Wed Jun 30 13:13:42 EDT 2010

Henning Thielemann wrote on Haskell Cafe:
>> Attached is a program with a space leak...
>> I have coded a simple 'map' function, once using unsafePerformIO and
>> once without. UnsafePerformIO has a space leak in some circumstances.
>> In the main program I demonstrate cases with and without space leak.
>> Without space leak the program writes a file to the disk until it
>> is full.

Bertram Felgenhauer wrote:
> The program relies on the GC doing short-cut evaluation of record
> selectors to avoid a space leak...
> Use of suffix: Due to the call of  Main.go1  this is *not* a record
> selector. It is compiled to an actual case expression, which to the
> garbage collector looks just like an ordinary thunk. A reference to
> Main.ds is kept around until the suffix is about to be processed
> and a memory leak ensues.
> The good news is that the problem is completely unrelated to
> unsafePerformIO (the presence of unsafePerformIO makes optimisations
> more difficult, but any pure function of sufficient complexity would
> have the same effect).

Is there already a GHC Trac bug for this?

Link to Bertram's original email, with detailed analysis of the
GHC Core:



More information about the Glasgow-haskell-users mailing list