Opened 16 years ago
Closed 14 years ago
#2002 closed defect (fixed)
python bindings are leaking memory
Reported by: | Even Rouault | Owned by: | hobu |
---|---|---|---|
Priority: | normal | Milestone: | 1.7.0 |
Component: | PythonBindings | Version: | svn-trunk |
Severity: | normal | Keywords: | |
Cc: | warmerdam, Kyle Shannon |
Description
I have run autotest under valgrind and found memory leaks in GDAL itself (most of them fixed now), but also in the python bindings themselves. I think one of them is OGRGeometry not being freed. Even without Valgrind, you can see it with the modified ogr_wkbwkt_geom.py (geometries created and destroyed in a huge loop). The python process memory doesn't stop increasing.
Attachments (3)
Change History (14)
by , 16 years ago
Attachment: | ogr_wkbwkt_geom_bigloop.py added |
---|
by , 16 years ago
Attachment: | ogr_wkbwkt_geom_valgrind_log.txt added |
---|
Extract from "valgrind --trace-children=yes --leak-check=full ./ogr_wkbwkt_geom.py"
comment:1 by , 16 years ago
I think this is fixed in r12851 for the ng bindings. Please regenerate and confirm.
by , 16 years ago
Attachment: | remaining_leaks_after_r12855.txt added |
---|
comment:2 by , 16 years ago
Cc: | added |
---|
comment:3 by , 16 years ago
Unless they are obvious or simple, I don't think we can do too much more on this one for 1.5. Two of the leaks (_Dict and ReadDir) are related to swig typemaps that would need to be changed for all languages. It is too late for those kinds of changes...
comment:5 by , 15 years ago
Howard, I think the following patch fixes the leak in _Dict.
Index: include/python/typemaps_python.i =================================================================== --- include/python/typemaps_python.i (révision 15995) +++ include/python/typemaps_python.i (copie de travail) @@ -375,6 +375,8 @@ PyObject *nm = PyString_FromString( keyptr ); PyObject *val = PyString_FromString( valptr ); PyDict_SetItem($result, nm, val ); + Py_DECREF(nm); + Py_DECREF(val); CPLFree( keyptr ); } stringarray++; @@ -484,6 +486,27 @@ } }
It fixes leaks for following snippet :
import gdal for i in range(1000000): md = drv.GetMetadata() print md['DMD_EXTENSION']
comment:6 by , 15 years ago
Arg, I meant :
import gdal drv = gdal.GetDriverByName('GTiff') for i in range(100000): md = drv.GetMetadata() print md['DMD_EXTENSION']
comment:7 by , 15 years ago
Milestone: | 1.6.1 → 1.7.0 |
---|
I've commited the above fix, as well as another one that would need work in other bindings, in r16031
comment:8 by , 15 years ago
comment:9 by , 15 years ago
Memory leaks when translating python sequence to C arrays fixed in trunk (16452) and in branches/1.6 (r16453)
comment:10 by , 15 years ago
Cc: | added |
---|
comment:11 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I am not aware of any remaining leaks in python bindings. Closing
Modified version of ogr_wkbwkt_geom.py