[Gdal-dev] References and scripting language bindings
Frank Warmerdam
warmerdam at pobox.com
Thu Sep 15 10:17:46 EDT 2005
On 9/15/05, Ari Jolma <ari.jolma at tkk.fi> wrote:
> Hi, this problem was discussed on IRC yesterday but I'm slow to
> understand, so I try to describe the problem again and think about a
> solution.
>
> The problem is that if you do something like
>
> layer = datasource.Open('data').GetLayerByIndex(0)
> print layer.Name
Ari,
To clarify for the list the problem you point out has
existed in the Python OGR bindings (and for that matter
in the GDAL bindings) as long as they have existed. The
requirement so far has been for the script writer to keep
a reference to the datasource until they are done using
objects owned by the datasource such as layers (or bands
in GDAL's case).
While this is not a terrible onerous requirement, it does violate
the reasonable expectation of the scripter, and introduces an
easy way to cause unexpected crashes which is undesirable.
So, the "safe" version of your code would be:
ds = ogr.Open("data")
layer = layer.GetLayerByIndex(0)
... do stuff with layer
ds = None
l
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