Memory leak when leaving 'each' loop prematurely

50 views
Skip to first unread message

Terris

unread,
Mar 28, 2014, 6:02:59 PM3/28/14
to dbm-...@googlegroups.com
use DBM::Deep;

my %db;

tie %db, "DBM::Deep", "foo.db";
$db{ 'a' } = { 'b' => { } };

untie %db;

for ( ;; ) {
    tie %db, "DBM::Deep", "foo.db";

    my $hash = $db{'a'};

    while ( each %{$hash} ) {
        last;
    }

   untie %db;
}

If you comment out the 'last' in the while loop, the leak will disappear. I also tied the next_key API. That didn't fix the problem. I tried many things - e.g., weaken, calling keys on the 'a' hash, using OO instead of tie, closing via stuff like "tied %db->engine->close" and on and on (I spent several days working on alternatives). The only thing that fixes the leak is to use "each" all the way to the end of the hash prior to untie.

This isn't a special case, either. For me, it happens to every hash stored in DBM::Deep.

Terris

Rob Kinyon

unread,
Mar 30, 2014, 8:19:37 PM3/30/14
to DBM::Deep
I'm really sorry to hear that there's a memory leak that's causing you
issues. Could you take this work and bundle it as a test we can put
into our t/ folder? I would be delighted to take a pull request
against https://github.com/robkinyon/dbm-deep with this failing test.

Thanks,
Rob
> --
> You received this message because you are subscribed to the Google Groups
> "DBM-Deep" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dbm-deep+u...@googlegroups.com.
> To post to this group, send email to dbm-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/dbm-deep.
> For more options, visit https://groups.google.com/d/optout.



--
Thanks,
Rob Kinyon
http://greenfishbluefish.com/

Terris Linenbach

unread,
Mar 30, 2014, 8:29:33 PM3/30/14
to dbm-...@googlegroups.com
Hello,

How do you make a test for a memory leak? I can see the leak happening with top and ps. How do you make Perl see it?


Thanks,
Terris

Rob Kinyon

unread,
Apr 12, 2014, 10:11:04 AM4/12/14
to DBM::Deep
I'm sorry about taking so long to respond. I switched gmail clients
and didn't realize some emails weren't visible in my new client.

Memory leaks in Perl only happen when there are cycles. So, look at
http://search.cpan.org/~petdance/Test-Memory-Cycle-1.04/Cycle.pm

Terris

unread,
May 28, 2014, 5:05:24 PM5/28/14
to dbm-...@googlegroups.com
memory_cycle_ok fails to find any cycles in \%db or $hash, so I'm still at a loss for how to write a unit test. 

Something is holding onto memory allocated by DBM::Deep that I am unable to get to.


Thanks,

Terris

Terris

unread,
May 28, 2014, 5:35:47 PM5/28/14
to dbm-...@googlegroups.com
By the way, the above program eventually terminates with the error:

DBM::Deep: Cannot sysopen file 'foo.db': Too many open files


Reply all
Reply to author
Forward
0 new messages