> In this Brave New World of DOD and GCC, what guarantees (if any)
> will we be making at the Perl 6 language level for the timely calling of
> object destructors at scope exit?

>From the straight GC perspective, none. There might be workarounds at
higher-levels, however.

> ie the classic
>
>     { my $fh = IO::File->new(...); .... }
>
> I know there's been lots of discussion on this over the months,
> but I'm slighly confused as to what the outcome was.

I'm not sure if there ever was a consensus. A few ideas that I recall
being brought up were:

a) allow the ability to force a DOD run at block exit. This would emulate
perl5 behavior, and would be necessary when porting perl5 code with
DESTROY methods. I can imagine having a "block-exit-var-in-scope" flag
somewhere, that's set when we create a magic filehandle var, and possibly
unset with each dod run if the variable goes out of scope. When this flag
is set, the interpreter can force a DOD on on some block_exit() opcode, or
whatever the interface.

b) We can make a special property for these variables:
my $fh is stack_freed = IO::File->new(...);
When this variable's stack frame goes out of scope, it automatically has
it's destructor called, regardless of other references, since it can't
detect them. It would leave the actual PMC header as "live" until the next
DOD pass, when it would be truly freed. If the next DOD pass finds it
alive, it could barf. This isn't entirely safe, but it does offer the best
performance, I think.

c) similar to b, but more programmer-directed. I believe .NET has two
concepts of destruction. IO filehandles can have an active destroy method
called directly on them with 'delete someobject', leaving the actual
memory hanging around until the next GC (dod) run, at which point it
really deletes the header.

..NET improves upon Java's inability to give timely constructors to
objects, by allowing the user to manually delete things when they know
there are no other references for things that need to free resources.


Other than the above, I'm not sure what other methods could be used to
force destruction. And I'm not sure if a decree has been made about what
Perl6 will do.

Mike Lambert

Reply via email to