Damien Neil wrote:
DN> {
DN> my $fh = IO::File->new("file");
DN> do_stuff($fh);
DN> }
DN>
DN> sub do_stuff { ... }
Simon Cozens wrote:
SC> No, it can't, but it can certainly put a *test* for not having
SC> references there.
Dan Sugalski wrote:
DS> Yes it can tell, actually--we do have the full bytecode to the sub
DS> available to us ...
Dataflow can tell you a lot, but the garbage collector can provide
info too. An object can never point to an object younger than itself.
If the stack is the youngest generation, then whenever something on the
stack gets stored in an older object the stack object ages.
If we still have a young $fh when do_stuff() returns, then the object is
safe to collect as long as we know that the scope owning $fh isn't
returning it. We don't need dataflow for the functions we call; we just
need dataflow for the current scope. (We also have to run a normal
traversing collection on the stack -- it isn't good enough to just
$fh->DESTROY because $fh might be pointed to by another stack object.)
By the way, this is also a way to make finalizers useful most of the
time. We can collect (which means finalize) portions of the youngest
generation at the end of every scope. The only time you'd get hit with
a non-deterministic finalizer is if you ever saved the object in an
old generation.
By the way, a lot of people are confusing a PMC object with a Blessed
Perl Object. To the perl internals everything is an object with a vtbl.
Only some of those objects will be Blessed Perl Objects.
- Ken