http://qs321.pair.com?node_id=193313

Elian has asked for the wisdom of the Perl Monks concerning the following question:

Here's a question for everyone. We're finalizing Parrot's object/variable destruction guarantees, and I'm trying to find out the common cases where dead-on timely destruction of objects is necessary, such that the lack of timely destruction would alter the semantics of the program badly enough to break it. With that in mind, I'm looking to tap the experience of the Monastery for such things. This is the last real chance to chime in--anything after this will have to be hacked in and likely will be slowish.

Keep in mind the following things:

  • Don't worry about guts-level things (memory usage and such). That's my problem, and we've got it covered already
  • You can install block-exit handlers, including in your caller's block, so you don't have to play DESTROY games to get lexical exit actions.
  • Allocation failure (for example running out of filehandles) will trigger a GC sweep and retry of the failing operation, so your program won't run out of things for lack of timely cleanup.
I'm currently aware of exactly one case where this can be an issue. To wit:
{ my $foo; open $foo, "<bar.txt"; print "Baz\n"; } { my $foo; open $foo, "<bar.txt"; print "xyzzy\n"; }
where not doing timely destruction of the filehandle will potentially end up doing odd things to the program. Locks and such on files fall in the same general category. (This can be dealt with by having open push a GC sweep on the list of block exit handlers, but I can see niggly issues there)

Anyone have any others? Note that I don't generally consider a delay in cleaning up after a lexically scoped thingie that's escaped its scope a big deal. (For example, when a filehandle gets put in a global array that's later completely cleaned out) I can be convinced otherwise with sufficient argument, of course. :)

Update by myocom: Added <readmore> tag