[Gdal-dev] On Feature.setGeometryDirectly SWIG bindings
Tamas Szekeres
szekerest at gmail.com
Sun Mar 18 13:51:06 EDT 2007
2007/3/18, Ari Jolma <ari.jolma at tkk.fi>:
> Andrea Aime kirjoitti:
> >
> > 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.
>
> AFAI understand the SWIGTYPE *DISOWN that is used with that method
> should take care of the issue. The garbage collection system of the
> bound language should not deallocate the C++ object if it does not own it.
>
> On the other hand, one method which seems to be missing DISOWN, is the
> constructor of Feature. Since it assumes the ownership of the
> FeatureDefinition (which however is not usually owned by the bound
> language to begin with) it should be disowned.
>
The current implementation of OGRFeatureDefnShadow is confusing and I
doubt if it's working correctly as it stands. We can see some kind of
reference counting implemented inside OGRFeatureDefn, however the
destructor of OGRFeatureDefnShadow calls OGR_FD_Destroy regardless of
the actual reference count value. It would be better to call
OGR_FD_Release instead.
Apparently we should not mix the disown and refcount philosophy
because it may lead to various unpredictable problems in the future.
Best regards,
Tamas
More information about the Gdal-dev
mailing list