Finalizers: conclusion?

Alastair Reid alastair at reid-consulting-uk.ltd.uk
Tue Oct 22 06:10:03 EDT 2002


<alastair at reid-consulting-uk.ltd.uk> pisze:
> keepAlive x y ensures that the finalizer for y is not run 
> until after the finalizer for x has run to completion.

Marcin:
> What if I do keepAlive p1 p2 >> keepAlive p2 p1?  They will never be
> collected?

Correct.

I'm a bit vague about what liveness dependencies are for.

What I was thinking was that you'd use it if the C object for p1
refers to the C object pointed to by p2 and the finalizer for p1
required that the C object pointed to by p1 to be alive.  In this
case, it would be an error to finalize p2 before you finalize p1 and
my semantics is the only one that will work.

If that is what liveness dependencies are for, then the programmer
made a mistake when they wrote:

  keepAlive p1 p2 >> keepAlive p2 p1

This would mean that the objects pointed to by p1 and p2 both have
pointers to the other and that it isn't possible to finalize them
independently (and, obviously, we have no way to finalize them
collectively, either).


Can those who use liveness dependencies correct my understanding of
what they are for?

--
Alastair









More information about the FFI mailing list