[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

SVN::Client -- why does this leak?

From: Nik Clayton <nik_at_ngo.org.uk>
Date: 2006-11-09 13:43:32 CET

Hi,

I've just spent some time tracking down a memory leak in some code that uses
SVN::Client.

Attached is a test that demonstrates the problem. It boils down to this:

    sub run {
        my $ctx = SVN::Client->new();
        my $pool = SVN::Pool->new_default();
        my $r = run_cmd($ctx);
        $pool->clear();

        return $r;
    }

That leaks memory. Specifically, it leaks at the first line. If the first
two lines are swapped around:

        my $pool = SVN::Pool->new_default();
        my $ctx = SVN::Client->new();

        ...

There's no leak.

My problem is that I don't understand why. I've read the pool usage
conventions section in hacking.html, and the SVN::Pool section in SVN::Core,
and I thought that since $ctx is going to drop out of scope at the end of
run() it's going to be automatically garbage collected, and any pool it
might have created will be cleaned up.

Is this a bug in my understanding of how things work, or a bug in the
SVN::Client implementation?

Attached is leak.pl. Run it, giving a URI as the first parameter. It'll
try and SVN::Client::cat() that URI 1,000 times (printing a '.' every 100
iterations). In another window run top(1), or similar, and observe how the
memory usage for the program keeps climbing.

If you then edit leak.pl, and swap the order of the first two lines in run()
and re-run it (again, monitoring with top(1) or similar) you'll see the
memory usage stays steady.

N

#!/usr/bin/perl

use strict;
use warnings;

use SVN::Client;

my $uri = shift || 'file:///home/nik/.svk/jc/local/CPAN/SVN-Web/branches/svn-client/Build.PL';

my %REPOS;

$| = 1;
foreach (1 .. 1_000) {
    run();
    if($_ % 100 == 0) {
        print '.';
        sleep 1;
    }
}

print "\n";

exit;

sub run {
    my $ctx = SVN::Client->new();
    my $pool = SVN::Pool->new_default();
    my $out = run_cat($ctx);
    $pool->clear();
    return $out;
}

sub run_cat {
    my $ctx = shift;

    my($fh, $fc) = (undef, '');
    open($fh, '>', \$fc);
    $ctx->cat($fh, $uri, 'HEAD');
    close($fh);

    return $fc;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Nov 9 23:37:52 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.