[geos-devel] Finding the Leak

Martin Davis mbdavis at refractions.net
Mon Aug 18 20:06:20 EDT 2008


That makes sense to me.  In JTS-land, PreparedGeometry was intended to 
be a "decorator" for Geometry.  (Although this is really a moot point in 
Java, since GC handles all magically....)

Under this pattern, the decorated geometry must be deleted after the PG 
is deleted, by the calling code.

Next step is to try it and see!

Oh, and yes, the Geometry needs to outlive the PG...

Paul Ramsey wrote:
> I had a few spare minutes today and poked around the area of the
> biggest leak...
>
> I see this construct in the PostGIS side in get_prepared_geometry_cache
>
> 		if ( !cache->prepared_geom )
> 		{
> 			LWDEBUGF(3, "get_prepared_geometry_cache: preparing obj");
> 			
> 			g = POSTGIS2GEOS( serialized_geom);
> 			cache->prepared_geom = GEOSPrepare( g);
> 		}
>
> So, a GEOS geometry is being created, and then converted into a
> prepared geometry, but *not* destroyed.  Attempting to destroy the
> geometry right away leads to a crash, presumably because the
> PreparedGeometry contains a reference to it in baseGeom?
>
> Later in the life cycle, the prepared geometry gets destroyed,
>
> 		GEOSPreparedGeom_destroy( cache->prepared_geom);
>
> But, in the PreparedGeometry destructor, the baseGeom is not destroyed...
>
> PreparedPolygon::
> ~PreparedPolygon( )
> {
>         delete segIntFinder;
>         delete ptOnGeomLoc;
>
>         for ( size_t i = 0, ni = segStrings.size(); i < ni; i++ )
>         {
>                 delete segStrings[ i ]->getCoordinates();
>                 delete segStrings[ i ];
>         }
> }
>
> I guess this makes sense (not to always destroy the base geometry in
> the GEOS code), but in our code that means the geometry is allocated
> but not destroyed, yes?
>
> Can saner heads than me confirm my analysis?
>
> P.
> _______________________________________________
> geos-devel mailing list
> geos-devel at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geos-devel
>
>   

-- 
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022



More information about the geos-devel mailing list