[Gdal-dev] NG Python bindings, and SWIG 1.3.29
Mateusz Loskot
mateusz at loskot.net
Wed May 24 16:24:08 EDT 2006
Frank Warmerdam wrote:
> I'm following up on failures in the autotest suite with the NG Python
> bindings, especially when built with SWIG 1.3.29 (the most recent public
> release of SWIG). It seems that invoking Destroy() or Release() on an
> ogr.DataSource is *not* causing it to be closed immediately and this is
> causing serious problems for tests that require this.
>
> A few questions:
> o The committed python wrappers seem to work substantially better than the
> ones I generate myself. Are the committed bindings generated with an
> older or a newer SWIG than 1.3.29?
Frank,
I'd like to add myself to this question :-)
> o Are there any suggestions on how to force immediate deletion in the
> ogr.DataSource destructor? Currently this just seems to decrement the
> Python reference count leaving it up to the Python VM to invoke the
> close function when it pleases.
Do you mean that explicit call of __del__ in Destroy() does not cause
object deletion?
There may be a few reasons of this issue:
- reference to DataSource still present, so then GC won't delete DataSource
- cyclic references between DataSource and o
if a is a DataSource then you may try to call:
del a
but this will *only* decrement reference counter and call __del__ dctor
only if refcounter is 0. So, in following case, __del__ won't be called:
a = MyClass()
b = a
del a # <----
Another option is to cause deletion by assigning None to DataSource
instance:
a = None
Calling __del__ explicitly won't promise that the object is deleted. It
still depends if there are any references existing.
Summarizing, I'd try to assing None at the first place:
def Destroy(self):
self = None
Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
More information about the Gdal-dev
mailing list