4. What is global
destruction?
• Perl has a couple of run-time phases:
BEGIN, CHECK, UNITCHECK, INIT,
runloop, END, DESTRUCT
• perldoc perlmod
Thursday, May 8, 14
5. What is global
destruction?
• BEGIN, CHECK, UNITCHECK, INIT,
runloop, END, DESTRUCT
• DESTRUCT cannot be called by
DESTRUCT {} blocks.
Thursday, May 8, 14
6. What is global
destruction?
• BEGIN, CHECK, UNITCHECK, INIT,
runloop, END, DESTRUCT
• DESTRUCT cannot be called by
DESTRUCT {} blocks.
• the runloop neither
Thursday, May 8, 14
7. DESTRUCT
• DESTRUCT is executed after
PerlIO_destruct and before PerlIO_clean
• DESTRUCT calls DESTROY methods on all
objects which do have a DESTROY method
(sv_clean_obj)
Thursday, May 8, 14
9. DESTRUCT
• Beware! Our current perlcc compiler does
not do global destruction.
• 2nd warning: our variables behave like
globals! Use only my, not our
Thursday, May 8, 14
10. package FINALE;
{
$ref3 = bless ["ok - package destructionn"];
my $ref2 = bless ["ok - lexical destructionn"];
our $ref4 = bless ["ok - our destructionn"];
local $ref1 = bless ["ok - dynamic destructionn"];
1;
}
DESTROY {
print $_[0][0];
}
=>
ok - dynamic destruction
ok - lexical destruction
ok - package destruction
ok - our destruction
DESTRUCT
Thursday, May 8, 14
11. perl debugging: -DD (-D? => D Cleaning up)
$ ./ccode197_o3 -DD
EXECUTING...
ok - dynamic destruction
ok - lexical destruction
Cursing named global static sv_arena:
Calling FINALE::DESTROY
ok - package destruction
sv_arena: 0x7ff9b982f600 - 0x7ff9b98305f0 (170)
sv_arena: 0x7ff9b982ae00 - 0x7ff9b982bdf0 (170)
sv_arena: 0x7ff9b9807800 - 0x7ff9b98087f0 (170)
Cleaning named glob IO object:
SV = PVIO(0x7ff9b982ce00) at 0x7ff9b982b7a8
REFCNT = 2
FLAGS = (OBJECT)
STASH = 0x7ff9b982b268! "IO::File"
...
DESTRUCT
Thursday, May 8, 14
12. ok - dynamic destruction
ok - lexical destruction
Cursing named global static sv_arena:
Calling FINALE::DESTROY
ok - package destruction
Cleaning object ref:
SV = IV(0x10076dce8) at 0x10076dcf8
REFCNT = 1
FLAGS = (ROK)
RV = 0x7fc549802aa8
SV = PVAV(0x7fc549005530) at 0x7fc549802aa8
FLAGS = (OBJECT)
STASH = 0x7fc5490287f8! "FINALE"
FLAGS = (REAL)
Elt No. 0
SV = PV(0x7fc549002780) at 0x7fc549802ac0
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x7fc548d0ab50 "ok - our destructionn"0
CUR = 21
LEN = 32
ok - our destruction
DESTRUCT
Thursday, May 8, 14
14. DESTRUCT
• Beware! Our current perlcc compiler does
not do global destruction.
• The new 5.14 compiler can do global
destruction, but this is not stable yet
Thursday, May 8, 14
15. Takeaway
package FINALE;
{
$ref3 = bless ["ok - package destructionn"];
my $ref2 = bless ["ok - lexical destructionn"];
our $ref4 = bless ["ok - our destructionn"];
local $ref1 = bless ["ok - dynamic destructionn"];
1;
}
DESTROY {
print $_[0][0];
}
Never use global destruction
Thursday, May 8, 14
16. Takeaway
package FINALE;
{
$ref3 = bless ["ok - package destructionn"];
my $ref2 = bless ["ok - lexical destructionn"];
our $ref4 = bless ["ok - our destructionn"];
local $ref1 = bless ["ok - dynamic destructionn"];
1;
}
DESTROY {
print $_[0][0];
}
Never use global destruction
Never use our objects, always my
Thursday, May 8, 14
17. Why?
• With old perlcc DESTROY methods of
global or our objects are not called.
Thursday, May 8, 14