mla has asked for the wisdom of the Perl Monks concerning the following question:
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';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: explicitly calling destructor
by diotalevi (Canon) on May 15, 2003 at 23:05 UTC | |
by mla (Beadle) on May 15, 2003 at 23:39 UTC | |
by diotalevi (Canon) on May 15, 2003 at 23:43 UTC | |
by Jenda (Abbot) on May 16, 2003 at 15:20 UTC | |
|
Re: explicitly calling destructor
by iburrell (Chaplain) on May 15, 2003 at 23:45 UTC | |
|
•Re: explicitly calling destructor
by merlyn (Sage) on May 16, 2003 at 09:26 UTC | |
|
Re: explicitly calling destructor
by hossman (Prior) on May 16, 2003 at 00:49 UTC | |
by mla (Beadle) on May 16, 2003 at 02:18 UTC | |
by hossman (Prior) on May 16, 2003 at 06:50 UTC | |
by mla (Beadle) on May 16, 2003 at 07:55 UTC | |
by edoc (Chaplain) on May 16, 2003 at 13:30 UTC | |
| |
by LanceDeeply (Chaplain) on May 16, 2003 at 18:09 UTC |