[Haskell-cafe] Re: FPS: Finalizers not running (was Memory
usageoutside of the Haskell heap)
Simon Marlow
simonmar at microsoft.com
Mon Nov 7 08:16:54 EST 2005
On 06 November 2005 18:38, Joel Reymont wrote:
> You need to do something like this to force them to run, apparently
>
> main = do foo $ Prelude.concat $ replicate 100 data_
>
> Just triggering the GC with performGC doesn't do it.
>
> The really odd thing is that if I setup a C finalizer (see below)
> then it's triggered once and the whole thing crashes with a bus
> error. Duncan reported that it segfaulted for him as well.
>
> installFinalizer fps@(P.PS fp _ _) =
> addForeignPtrFinalizer finalizer fp
>
> foreign import ccall unsafe "finalizer" finalizer :: FinalizerPtr
> Word8
>
> where the finalizer itself is
>
> #include <stdio.h>
>
> void finalizer(char *p) {
> printf("--- Finalized: %x\n", p);
> }
This crash is due to driver error, I'm afraid. You should have written:
foreign import ccall unsafe "&finalizer"
finalizer :: FinalizerPtr Word8
(note the "&").
Cheers,
Simon
More information about the Haskell-Cafe
mailing list