I'm using very big memory layers:

Is there any way to empty (fast), destroy or clean a layer in memory from an script without exit from this script ?

  • Perhaps this post might help: Deleting all Features of a Vector Layer in pyQGIS. I don't see why the solution to that post shouldn't work for memory layers. – Joseph Dec 8 '16 at 11:09
  • 1
    Thanks, Joseph, The solutions discussed in the link you comment are the closest to what I thought. Looking at the sources of QGIS (and GDAL / OGR) I have seen that there is no method like: layer.empy () or similar – Juanma Font Dec 9 '16 at 8:13

Have you tried


These should remove the reference to the layer and call the layer destructor.


In your script you can use:


assuming that the name of memory layer is 'mem_layer'.

  • You have to add the layer to the registry in order to remove it (and delete it) in this case. If you are just working with arrays in memory then you want to delete the handle without adding it to the registry (saving time). – A.A Dec 8 '16 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.