[plt-scheme] Re: Finalizer or custodian for extension's resources?
Matthew Flatt wrote:
> But I can't reproduce your test results. With strong=0, I get a ~Foo()
> when either a couple of GCs happen or the custodian is shut down (e.g.,
> when the "Execute" button is pushed in DrScheme for a new REPL). If the
> custodian is shut down, I get a redundant ~Foo() on a later GC from the
> finalizer.
>
> I wonder whether the problem is just the number of GCs. (Normally, one
> is not enough, and partly that's due to conservative GC.) I have to run
> (collect-garbage) a couple of times to get ~Foo() without shutting down
> the custodian.
I wasn't aware I would need several GCs sometimes. Now I am indeed
getting your results. :)
There's still a problem though. ~Foo() should only be called *once* per
Foo(). How would I go about doing that? Should the finalizer remove the
custodian and vice versa? I don't really know how to accomplish that. I
guess I could store the Scheme_Custodian_Reference* along with the Foo
instance. Or perhaps I could store an extra boolean which indicates
whether the instance has been destroyed or not. Both methods seem like
kluges though.
Any ideas?
Thanks so far,
Dirk Gerrits