Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: if(my) scope

by dada (Chaplain)
on Apr 16, 2009 at 10:49 UTC ( #757932=note: print w/replies, xml ) Need Help??

in reply to if(my) scope

perltoot says:
Perl's notion of the right time to call a destructor is not well-defined currently, which is why your destructors should not rely on when they are called.
so the answer is: none of your business :-)


King of Laziness, Wizard of Impatience, Lord of Hubris

Replies are listed 'Best First'.
Re^2: if(my) scope
by DStaal (Chaplain) on Apr 16, 2009 at 13:54 UTC

    Just to expand on the above:

    In garbage-collected languages it is generally a bad idea to worry about exactly when a specific piece of data is garbage collected. It will happen at the runtime's convenience, no sooner, and no later. Doing immediate collection is generally more work (at runtime) than it is ever going to be worth.

    So, expect that timing to change on different boxes, runs, and if you recompile. The only thing you are in good shape to be sure of it that it will happen after the variable has gone out of scope.

      Expanding a bit further.

      That comment only applies to mark-and-sweep type garbage collection. As a general rule, Perl's reference-counted garbage collection is deterministic and mostly handles as you would expect. (Present case excepted, of course.)

      Personally, I regret the loss of a defined, consistent object lifetime caused by using mark-and-sweep. Having the lifetime of a object determine the timing of events is quite useful. It's one of the reasons I prefer Perl and C++ to Java.

      G. Wade

        case in point:

        package H; sub DESTROY { print "DESTROY\n"; } sub new { my $class = shift; bless {}, $class; } { if(my $h = H->new()) { print "IN\n"; undef $h; } print "\$h out of scope\n"; } print "why now?\n";


        IN DESTROY $h out of scope why now?

        As does:

        package H; sub DESTROY { print "DESTROY\n"; } sub new { my $class = shift; bless {}, $class; } { { if(my $h = H->new()) { print "IN\n"; } } print "\$h out of scope\n"; } print "why now?\n";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://757932]
[choroba]: Will Glasgow have been out of the EU by that time already?
[LanX]: nope
hippo might venture to YAPC::EU.
[choroba]: YAPC::YAEC (yet another European country)
[LanX]: they are proposing an infinite transition phase now ...
[choroba]: infinite transition implies infinite money!
[LanX]: ... ehm ..."open ended" ;-)
[LanX]: anyway ... the (official) leave date is in March 2019
[marto]: choroba no :P

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2018-02-23 10:57 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (301 votes). Check out past polls.