[gdal-dev] Re: GDAL Java Binding meomory problem under intensive method calls

Even Rouault even.rouault at mines-paris.org
Sat Jan 7 08:50:58 EST 2012

Le samedi 07 janvier 2012 14:18:12, easyl a écrit :
> Ja, I am re-writing now the ogrtindex.cpp from
> http://svn.osgeo.org/gdal/trunk/gdal/apps/ogrtindex.cpp in Java.
> It seems be rather easier than ogr2ogr or ogrinfo.
> I found a Clone call in cpp code
>    poFeatureDefn = poLayer->GetLayerDefn()->Clone();
> But in Java binding (1.8.1) there is no Clone() for LayerDefn!
> I don't think that would be a good idea that I in java code just ignore
> Clone() call.
> Maybe I need to keep the 'poLayer' not deleted? so that 'poFeatureDefn' can
> still have reference on the LayerDefn.

You should be able to implement the one at line 294 that way :

FeatureDefn poSrcFeatureDefn = poLayer.GetLayerDefn();
poFeatureDefn = new FeatureDefn(poSrcFeatureDefn.GetName());
for(int i = 0; i < poSrcFeatureDefn.GetFieldCount(); i++)

And I believe that the one at line 423 isn't used at all afterwards. So just 
emptying this line should work.

More generally, with the OGR Java bindings, avoid using the delete() methods, 
except on the datasource objects, where it is necessary to close properly the 
native file handles. The other type of objects should be garbage collected 

> Another question is, where can I check in my Java code for ogrtindex to
> share with everyone.

You can file a ticket in http://trac.osgeo.org/gdal/newticket (you need to 
create a OSGeo id first if not already done) and attach your new file in it.

More information about the gdal-dev mailing list