[Qgis-user] reduce number of open files in pyqgis script
Greg Troxel
gdt at lexort.com
Fri Dec 26 07:48:28 PST 2025
Martin Landa via QGIS-User <qgis-user at lists.osgeo.org> writes:
> for sublayer in layers:
> name = sublayer.name()
> layer = QgsVectorLayer(sublayer.uri(), 'ogr')
>
> clipped_layer = clip_layer(layer, extent, layer.name())
>
> del layer
>
> print(name, open_files_count())
> if clipped_layer.featureCount() == 0:
> del clipped_layer
> continue
> clipped_layers.append(clipped_layer)
> """
I would suggest reading the gdal code to try to understand this.
Looking at your code above, I wonder if the layer returned by clip_layer
holds a reference to the first argument. (This should be easy to
understand from code reading).
More information about the QGIS-User
mailing list