如何在Perl中完全删除包?这不仅意味着包变量,还意味着Perl更新以处理继承更改和其他事情的任何魔法表。
这个简单的测试:
use warnings; use strict;
use Test::LeakTrace;
use Symbol 'delete_package';
leaktrace {
package test;
our $x = 1;
package main;
delete_package 'test';
};
结果如下:
leaked ARRAY(0x81c930) from /lib/perl5/5.10.1/Symbol.pm line 166.
leaked HASH(0x827760) from /lib/perl5/5.10.1/Symbol.pm line 166.
leaked SCALAR(0x821920) from /lib/perl5/5.10.1/Symbol.pm line 166.
使用
-verbose
的标志
leaktrace
结果在屏幕上的数据,我可以要求张贴。
如果排队的话情况会更糟
our @ISA = 'main';
已添加到
test
包裹:
leaked ARRAY(0x81cd10) from so.pl line 32.
leaked SCALAR(0x81c930) from so.pl line 32.
leaked ARRAY(0x8219d0) from so.pl line 32.
leaked HASH(0x8219c0) from so.pl line 32.
leaked SCALAR(0x8219b0) from so.pl line 32.
leaked HASH(0x8219a0) from so.pl line 32.
leaked SCALAR(0x821970) from /lib/perl5/5.10.1/Symbol.pm line 161.
leaked HASH(0x821950) from so.pl line 32.
leaked SCALAR(0x821940) from so.pl line 32.
our @ISA
为了说明这些确实是泄漏,而不仅仅是口译员的噪音:
my $num = 0;
while (1) {
no strict 'refs';
@{$num.'::ISA'} = 'main';
delete_package $num++;
}
delete_package
? 我还有别的事要做吗?