[QGIS-Developer] Memory Leak / Slowdown?

Drexel Peter Peter.Drexel at vorarlberg.at
Mon Apr 20 02:08:15 PDT 2020


Hi,
I use a Python-Script to load all shapefiles in a directory tree one by one and export the sld-files.
It works fine, but slows down incredible after ~100 files.
So I tried the following barebone script with just the essentials  (load shapefile, add it to the map canvas, remove it again and then clear the project) in a loop and I get the same behavior...

from datetime import datetime
for i in range(1, 1000):
                vlayer=QgsVectorLayer ("aShapeFile.shp" ,"run  " + str(i) + " at " + datetime.now().strftime('%H:%M:%S') ,"ogr")
                QgsProject.instance().addMapLayer(vlayer)
                QgsProject.instance().removeMapLayer(vlayer.id())
                QgsProject.instance().clear()

Same result,  the Script slows down after every iteration in the loop AND QGIS-memory consumption goes up!
Do I need to do some garbage cleaning / what am I doing wrong / is this a Memory leak?

Thanks everybody for any hints / help!

Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200420/e83eccd7/attachment.html>


More information about the QGIS-Developer mailing list