Bug report #17985
Huge memory leak with QgsFeature.attributes() in Python
|Category:||Python bindings / sipify|
|Affected QGIS version:||master||Regression?:||Yes|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||fixed/implemented|
|Crashes QGIS or corrupts data:||Yes||Copied to github as #:||25881|
Steps to reproduce:
Load a big layer with many NULL values
Run the python code:
for f in iface.activeLayer().getFeature():
And watch your memory go!
It's caused by the ConvertFromTypeCode in QgsAttributes.h/sip - commenting out the code which sets list items in the loop avoids the leak. Martin has also deduced that it's only triggered by the presence of NULL values in the list.
#1 Updated by Nyall Dawson over 3 years ago
Nathan reports that the leak is also present in the QgsFeature python code - e.g. calling
feature['my_attr'] will leak if the attribute is NULL.
To be precise - it's not technically a memory leak, it's just that Python is not garbage collecting these values.