Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I completely delete a package in Perl?
    text
    copied!<p>How do you completely delete a package in Perl? This means not only the package variables, but also any magic tables that Perl updates to handle inheritance changes and other things.</p> <p>This simple test:</p> <pre><code>use warnings; use strict; use Test::LeakTrace; use Symbol 'delete_package'; leaktrace { package test; our $x = 1; package main; delete_package 'test'; }; </code></pre> <p>results in the following output:</p> <pre><code>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. </code></pre> <p>Using the <code>-verbose</code> flag for <code>leaktrace</code> results in screenfuls of data which I can post on request.</p> <p>Things get worse if the line <code>our @ISA = 'main';</code> is added to the <code>test</code> package:</p> <pre><code>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. </code></pre> <p>Line 32 is where the <code>our @ISA</code> is.</p> <p>To illustrate that these are indeed leaks and not just noise from the interpreter:</p> <pre><code>my $num = 0; while (1) { no strict 'refs'; @{$num.'::ISA'} = 'main'; delete_package $num++; } </code></pre> <p>will eat memory at a constant rate </p> <p>So, is there a better way to get rid of a package than Symbol's <code>delete_package</code>? Is there something else that I have to do to help it along?</p> <p>I have seen the same behavior in 5.8.8, 5.10.1, and 5.12</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload