Ticket #1680 (closed defect: fixed)
NG SWIG OGRSpatialReference Ref Counts
| Reported by: | warmerdam | Owned by: | warmerdam |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.4.2 |
| Component: | PythonBindings | Version: | svn-trunk |
| Severity: | normal | Keywords: | refcounting OGRSpatialReference |
| Cc: | hobu |
Description
It seems that the OGRLayer::GetSpatialRef?() call in gdal/swig/include/ogr.i is not taking a reference on the returned OGRSpatialReference, and that such objects are not dereferenced when they are unreferenced from the script.
This leads to the situation, in python, where:
ds = ogr.Open( 'data/small_ntf.mif' )
srs = ds.GetLayer(0).GetSpatialRef()
ds = None
pm_value = srs.GetAttrValue( 'PROJCS|GEOGCS|PRIMEM',1)
does not work properly because by the time srs.GetAttrValue?() is called the SRS was already destroyed (when the datasource was destroyed).
Note that osr.py does implicitly get a reference when an OGRSpatialReference is directly created, and it is properly dereferenced on destruction.
I observed this in trunk.
While I'm marking this as PythonBindings?, I presume it applies to all NG swig bindings.
