[Gdal-dev] ogr.py - managing the lifetime of Geometry and Feature objects

Frank Warmerdam fwarmerdam at gmail.com
Sat Jan 22 01:18:56 EST 2005


Folks,

With encouragement (aka browbeating) from Howard Butler I have 
implemented logic in the python bindings of the OGRFeature and
OGRGeometry classes so that instances of ogr.Geometry and ogr.Feature
keep track whether they "own" the associated C++ object. 

When the python object is destroyed (it's reference count drops to 
zero) it will destroy the C++ object if it still owns it. 

So, if you call Layer.GetNextFeature() to get a feature, it will be
owned by you, and when the feature is no longer referenced from
Python it will be automatically destroyed. 

You are still free to explicitly destroy with the Destroy() method, 
in which case the "ownership" flag is cleared so no extra attempt
will be made to destroy it in the python object destructor.  So old
style "managed lifetimes" code will still be OK.

For geometries something similar is done. 

These changes will only affect those using the Python bindings
and all old code should still work.  In the future you should not need
to explicitly Destroy() features or geometries. 

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the Gdal-dev mailing list