[gdal-dev] Re: Memory leaks in Geo::OGR::Geometry Points() swig Perl function

Ari Jolma ari.jolma at gmail.com
Wed Mar 14 07:34:26 EDT 2012


On 03/14/2012 12:59 PM, Ivan Balashov wrote:
> Hello, Ari!
>
> We are using Geo::OGR perl library installed from FreeBSD gdal port 
> (http://www.freebsd.org/cgi/cvsweb.cgi/ports/graphics/gdal/) ver. 
> 1.8.1 with perl  v5.10.1 for geomery operations on forest fire 
> polygons, in particular, Points function.
> Long script runs leads to large memory consumption and process 
> termination by kernel kill signal.
> In attachment you can see the simple script that reproduce this memory 
> leak.
> I'm wathcin at 'top' while running this script and see the memory 
> allocated for this process growing.
> I appologize that it is memory leak within Points() function.
> In case of  $geom->GetPoint() call on LineString geometries the same 
> thing happens.
>
> Could you comment or help with this problem, or redirect me to 
> attached with this module person or tool to submit this bug?

Ivan,

I'm the right person to complain to as long as the problem is within 
Perl bindings. GDAL bugs are reported with http://trac.osgeo.org/gdal/ - 
you need to login with OSGeo account to create a ticket.

The code below creates a lot of geometries and from each it then crates 
a Perl object. Each call on Points method returns a reference to a new 
anonymous data structure. But at the end of each loop both the GDAL 
object and the Perl object should be destroyed.

When I run the code I also notice a lot of memory being used by the 
process. When I run the code (using 10, 100, 1000, and 10000 loops) 
under valgrind I don't see much suspicious things going on:

==4270== LEAK SUMMARY:
==4270==    definitely lost: 11,395 bytes in 21 blocks
==4270==    indirectly lost: 48,842 bytes in 17 blocks
==4270==      possibly lost: 2,209,528 bytes in 31,732 blocks
==4270==    still reachable: 8,094 bytes in 25 blocks
==4270==         suppressed: 0 bytes in 0 blocks

This is when I ran the code for 10000 loops. The definitely lost amount 
is the same as for 1000 loops. The possibly lost is only doubled from 
1000 loops.

Hm. Examining the bindings I find a suspicious thing happening. It seems 
that an empty Perl object may be created and then forgotten.

I'll look more into this later.

Ari

>
> Thank you!
>

the code:

#!/usr/local/bin/perl -w
use strict;
use warnings;
use Geo::OGR;

my $wkt = 'POLYGON((40 40,40 50,50 50,50 40,40 40))';

foreach (1..10000000)
{
     my $geom = Geo::OGR::CreateGeometryFromWkt($wkt);
     my $points_ref = $geom->Points();
}



More information about the gdal-dev mailing list