[Gdal-dev] On Feature.setGeometryDirectly SWIG bindings

Andrea Aime aaime at openplans.org
Sun Mar 18 11:38:38 EDT 2007


Hi,
playing with java and OGR I had quite a bit of JVM
breakages due to inconsistent/conflicting memory
handling on either side of the JNI fence.

One that has been tricky to identify is Feature.setGeometryDirectly.
This issue is there because every SWIG wrapper
does deallocate its C++ counterpart when garbage collected,
and thus the OGR Feature that got is geometry thru setGeometryDirectly
is left with a dangling reference. (since garbage collection is not
predictable, the error may occur a few seconds later, leaving
you wondering what went wrong).

That function has no special handling... as is, it should
be removed from the bindings of any language that has
garbage collection and finalization to avoid memory
handling issues.

The following chapters in the Swig guide:
http://www.swig.org/Doc1.3/CSharp.html#csharp_memory_management_objects
http://www.swig.org/Doc1.3/Java.html#java_memory_management_objects
seem to provide a solution for that issue, other than removing
the method.

Did anyone every used those typemaps?
Cheers
Andrea



More information about the Gdal-dev mailing list