I'm trying to find out why DESTROY is sometimes called twice on some of my objects.

I've boiled the issue down to this script:

#!/usr/bin/perl package MyModule; use Devel::Peek; sub new { print "IN NEW\n"; return bless {}; } sub DESTROY { print "======= BEGIN DESTROY:".$$."========\n"; # print Dump(@_); print "============ END DESTROY:".$$."========\n"; } 1; package main; use Net::Server::PreFork; my $hardtodestroy = new MyModule; Net::Server::PreFork->run(max_servers=>1, min_servers=>1, min_spare_se +rvers=>0, max_spare_servers=>0);

Try run it a few (10, 20,...) times interrupting it with Ctrl-C. Eventually you'll get a run like this:

2014/05/19-08:55:41 Server closing! ======= BEGIN DESTROY:9980======== ======= BEGIN DESTROY:9980======== ============ END DESTROY:9980======== ======= BEGIN DESTROY:9979======== ============ END DESTROY:9979========

?!?!!? ... why was DESTROY called twice in the same process? ... and why didn't it end?

Enabling Devel::Peek will reveal it's 2 difference references to the same Perl object.

I've reproduced the problem on Perl 5.10/Debian and Perl 5.14/Ubuntu. ... but have been unable to find anything similar by googling which couldn't be explained by some error in an XS module. ... but I think I've ruled that out in the above example.


In reply to Is this absurd, or have I not RTFM? by petermogensen

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.