1 Jan 2004 12:39
Re: Running a "final" finaliser
Adrian Hey <ahey <at> iee.org>
2004-01-01 11:39:33 GMT
2004-01-01 11:39:33 GMT
On Wednesday 31 Dec 2003 10:05 am, Adrian Hey wrote:
> On Wednesday 31 Dec 2003 8:56 am, Adrian Hey wrote:
> > Intended use is something like this...
> >
> > {-# notInline libXYZRef #-}
> > libXYZRef :: LibRef
> > libXYZRef = unsafePerformIO newLibRef
> >
> > main :: IO ()
> > main = finally (initLibXYZ >> userMain) (killLibRef libXYZRef
> > shutDownLibXYZ)
> > -- initLibXYZ and shutDownLibXYZ are Haskell bindings to functions
> > supplied -- by libXYZ
>
> Actually, using..
> main = finally (initLibXYZ >> userMain)
> (performGC >> killLibRef libXYZRef shutDownLibXYZ)
>
> seems to fix the problem, which isn't too surprising I guess.
> But then again, if this is a reliable solution there's no need
> for LibRef after all
Hmm, further experiments with creating zillions of garbage
ForeignPtrs (not just 1) reveals that the problem only occurs
if *no* garbage collection has occured before the program shuts
down. In other words, as long as at least one garbage collection
has occured, it doesn't matter if library shutdown occurs immediately
in response to killLibRef or if it's deferred until the reference
count hits zero as a result of finalisers being called. (This test
is without the explicit performGC of course.)
(Continue reading)
RSS Feed