[geos-devel] Memory leaks (?) experienced with WKTReader and WKBWriter

Sandro Santilli strk at keybit.net
Mon May 16 08:51:52 EDT 2011


On Mon, May 16, 2011 at 03:22:31PM +0300, Manos Karpathiotakis wrote:
> Hi all!!
> 
> I am currently using geos 3.2.0 in an implementation of mine. The classes I
> am mainly using are Geometry, WKTReader and WKBWriter.
> 
> However, after examining my code with valgrind, it seems that I am
> experiencing memory leaks from the two WKT classes.
> The block of code that contains those is the following:
> 
> WKTReader* reader;
> WKBWriter* writer;
> for (unsigned i = 1; i <= 1000000000; i++) {
>                 //
>                 //create the wkt geometry...
>                 //
> 
>                 string wkt = sObj.str();
> Geometry* geom = (*reader).read(wkt);
>                 (*writer).writeHEX(*geom,geo_values);
>  //reader->~WKTReader();
> //(*geom).~Geometry();
>  //free(geom);
> //delete reader;
> }
> 
> The lines commented at the end of the block are my attempts to perform
> garbage collection manually.
> So, my question is the following: Is there a specific way to destroy the
> Geometry/WKTReader/WKBWriter??
> Is it possible to avoid the leaks I am experiencing?

delete geom; // inside the loop
delete reader; delete writer; // outside the loop

-- strk;

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html


More information about the geos-devel mailing list