On Tue Jun 12 12:36:47 2012, rrfreimuth2@yahoo.com wrote:
Show quoted text> Hi,
>
> I'm not sure that it's circular, as $db never points to $db2 (but it
> wouldn't surprise me if ref-counting is somehow involved). I'm just
> using $db2 as a shortcut into a deeper level of the $db structure.
>
> Thanks for taking the time to look into this.
Devel::FindRef to the rescue!
Here is a variation of your script, with the output below. Notice that $db2 is still set even
after weakening.
use strict;
use warnings;
use DBM::Deep;
use Scalar::Util 'weaken';
my $db_file = 'href_nocopy';
{
my $db = DBM::Deep->new( $db_file );
$db->{key} = {};
weaken $db;
warn $db;
}
$db_file = 'href_copy';
{
my $db = DBM::Deep->new( $db_file );
$db->{key} = {};
my $db2 = $db->{key};
weaken $db;
weaken $db2;
warn $db;
warn $db2;
if ($db2) {
use Devel::FindRef;
print Devel'FindRef'track $db2;
}
}
__END__
Use of uninitialized value $db in warn at - line 14.
Warning: something's wrong at - line 14.
Use of uninitialized value $db in warn at - line 26.
Warning: something's wrong at - line 26.
DBM::Deep::Hash=HASH(0x33d9f0) at - line 27.
DBM::Deep::Hash=HASH(0x33d9f0) [refcount 3] is
+- referenced by REF(0x8515f0) [refcount 1], which is
| a temporary on the stack.
+- referenced by REF(0x8038d0) [refcount 1], which is
the member '0' of HASH(0x881f80) [refcount 1], which is
referenced by REF(0x8517c0) [refcount 1], which is
the member '609' of HASH(0x88c160) [refcount 1], which is
referenced by REF(0x88c150) [refcount 1], which is
the member 'cache' of DBM::Deep::Engine::File=HASH(0x87dec0) [refcount 1], which
is
referenced by REF(0x88c1b0) [refcount 1], which is
the member 'engine' of DBM::Deep::Hash=HASH(0x88c0f0) [refcount 2], which is
referenced by REF(0x88c1e0) [refcount 1], which is
referenced (in mg_obj) by 'P' type magic attached to
DBM::Deep::Hash=HASH(0x33d9f0) [refcount 3], which is
not referenced within the search depth.
I don’t have time to write tests for it right now, but I believe the attached patch will fix it.
Does it work for you? If so, I will put it in the next release, maybe in a couple of days.
Show quoted text>
> --- On Mon, 6/11/12, Father Chrysostomos via RT <bug-DBM-
> Deep@rt.cpan.org> wrote:
>
> From: Father Chrysostomos via RT <bug-DBM-Deep@rt.cpan.org>
> Subject: [rt.cpan.org #77746] Cannot delete DBM::Deep file after
> copying inner key (ref count issue?)
> To: RFREIMUTH@cpan.org
> Date: Monday, June 11, 2012, 12:56 AM
>
> <URL:
https://rt.cpan.org/Ticket/Display.html?id=77746 >
>
> On Sun Jun 10 22:22:46 2012, RFREIMUTH wrote:
> > $db_file = 'href_copy';
> >
> > {
> > my $db = DBM::Deep->new( $db_file );
> > $db->{key} = {};
> > my $db2 = $db->{key};
> > }
> >
> > print "\nDeleting $db_file\n";
> > unlink( $db_file ) || warn $!; # fails (permission denied)
>
> > Any ideas? I didn't find any documentation about this elsewhere.
>
> That sounds like a circular reference. Those are hard to track down,
> but I’ll try if I have time.
>