[Haskell-cafe] Re: FPS: Finalizers not running (was Memory usage outside of the Haskell heap)

Udo Stenzel u.stenzel at web.de
Mon Nov 7 07:32:13 EST 2005

Joel Reymont wrote:
> foo [] = return ()
> foo (x:xs) =
>     do let fps = P.packWords x
>        installFinalizer fps
>        putStrLn $ "fps: " ++ show fps
>        unsafeFinalize fps 	<---- ???
>        foo xs

Is it even possible for the compiler to finalize and gc `fps' at the
marked line?  Without the unsafeFinalize, `fps' is still in scope and
might be used after `foo xs' returns.  Is GHC supposed to see that `fps'
is no longer in use?  Does the following code work better?

> foo (x:xs) =
>     do do let fps = P.packWords x
>           installFinalizer fps
>           putStrLn $ "fps: " ++ show fps
>        foo xs

BTW, Joel, it seems, your code is creating lots of very short
FastPackedStrings.  That's useless, a list of Word8s could replace a
list of short FastPackedStrings at essentially no additional cost.  But
it would simplify the code a lot, overcome any problems with finalizers
in passing, and probably enable weird and wonderful optimizations by

Only long FastPackedStrings will be fast, and only if you're not growing
them in pieces, and if you're storing them for an extended time, and if
you're consuming them more than once.  It looks as if you're using them
four times wrong.

The most happy marriage I can imagine to myself would be the union of a
deaf man to a blind woman.  -- Samuel Taylor Coleridge
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20051107/e7c707d8/attachment.bin

More information about the Haskell-Cafe mailing list