I have an object that locks a resource and releases it on destruction. This is under mod_perl, and the object should be destroyed at the end of every request.

Unfortunately, a reference to the object is being maintained somewhere, I'm not sure where, which is preventing destruction and keeping the resource locked.

I need to locate those extra references, but as a short-term solution, I'd like to make sure the lock is released.

I could call the DESTROY method explicity, which would release the lock. But then, I want to make certain that DESTROY is not called again, implicitly, if/when the object is really reclaimed, since the lock will have already been released, making it unsafe.

If I reblessed the object into a null class, it seems like I'd be okay. Here's some example code. Does that make sense? Is there a better solution?

Thank you.

#!/usr/bin/perl -w package Null; use strict; our $AUTOLOAD; sub AUTOLOAD { warn __PACKAGE__ . " $AUTOLOAD CALLED" } package Foo; use strict; sub new { bless [], __PACKAGE__ } sub DESTROY { my $self = shift; warn __PACKAGE__ . " DESTROY CALLED"; } package main; my $s1 = Foo->new; my $s2 = $s1; $s1->DESTROY; bless $s1, 'Null';

In reply to explicitly calling destructor by mla

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.