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

Re: SVN::Client -- why does this leak?

From: Malcolm Rowe <malcolm-svn-dev_at_farside.org.uk>
Date: 2006-11-09 23:43:36 CET

On Thu, Nov 09, 2006 at 12:43:32PM +0000, Nik Clayton wrote:
> 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.
>

Right, because in the first case, the client context is instantiated
using the global default pool, so there's no pool to go out of scope.
In the second case, the client context is instantiated inside $pool, and
gets freed when $pool goes out of scope.

> 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.
>

It's the pool that's important, not the objects allocated within the
pool - and the global default pool never goes out of scope.

> iterations). In another window run top(1), or similar, and observe how the
> memory usage for the program keeps climbing.
>

(because we're allocating out of a single pool that's never destroyed or
cleared)

> 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.
>

(because we're creating and destroying a subpool for each call).

This seems like it's working as intended to me?

Regards,
Malcolm

  • application/pgp-signature attachment: stored
Received on Thu Nov 9 23:44:26 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.