in reply to my versus our, why is my slower when script ends (global cleanup)
The reason is simple , lexicals (my) are destroyed/destructored/cleanedup in-order
Where as, globals are cleaned up during "global destruction" before program exits but not in-order as there is no order they're globals
You can short-circuit cleanup with POSIX::exit() for even faster exit, but then destructors and stuff dont ...
Example
## $stuff not exist { our $stuff = 1234; } ## $stuff still exist { my $lexi = 1234; } ## $lexi cleaned up here but $stuff still exists { my $flexi = 1234; } ## $flexi cleanedup but stuff still exists exit; ## $stuff cleaned up here in whatever fast order it happens to come fr +om the perl memory stack
There are discussions on this just search for global destruction order, site:perlmonks.org global destruction order
see sub DESTROY: Strange ordering of object destruction (global destruction order not guaranteed, Re^3: when is destroy function called ( perl -d:Trace dalek ), Re^2: Perl Gtk2 - ->destroy() is Not Causing the Script to Exit
Why does Perl have this odd behavior during cleanup?
Heheh, its always funny when people (me too) say something is odd/weird ... almost as if they're trying to say I know stuff but this doesn't behave like it should (i used to think this but I know better now)... but what they really mean is always I don't know what should be happening, why is there a difference in what is happening, even if they don't think this is what they mean
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: my versus our, why is my slower when script ends (global cleanup)
by marioroy (Prior) on Apr 22, 2017 at 03:49 UTC |