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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |