You are reaching the limit of my understanding. Specifically, if you execute the script:
#!/usr/bin/perl use strict; use warnings; use 5.012; use Phases; my $main_closure = bless {name => 'main_closure'}, 'Phases'; sub closure { say $main_closure; } my $external = bless {name => 'external'}, 'Phases'; END { say 'Main END' } say 'Main Last line';
with the module
package Phases; use 5.012; BEGIN { say 'Phases BEGIN' } UNITCHECK { say 'Phases UNITCHECK' } CHECK { say 'Phases CHECK' } INIT { say 'Phases INIT' } END { say 'Phases END' } my $my = bless {name => 'my'}, __PACKAGE__; my $closure = bless {name => 'closure'}, __PACKAGE__; our $our = bless {name => 'our'}, __PACKAGE__; sub closure { print $closure; } sub DESTROY { my $self = shift or say 'Nothing passed to DESTROY' and return; my $name = $self->{name} || '<undef>'; say "Phases DESTROY $name" } 1;
(borrowed heavily from Know the phases of a Perl program’s execution) outputs
Phases BEGIN Phases UNITCHECK Phases DESTROY my Phases CHECK Phases INIT Main Last line Phases DESTROY external Main END Phases END Phases DESTROY closure Phases DESTROY our Phases DESTROY main_closure

What I hear you saying is that you problem happens between "Last line" and "Main END". Are there any variables scoped at script level going out of scope? If you have suspects, you can stick them into closures to make them persist longer; that might identify which package's destructor is responsible.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


In reply to Re^7: Hard to Debug windows memory error by kennethk
in thread Hard to Debug windows memory error by jandrew

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.