From b41878e960e499a6b2118180588be766b5555f56 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 16 Jan 2023 21:29:59 +0100 Subject: [PATCH] #2697 take only a single inverse at a time --- .../ifcopenshell/api/root/remove_product.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py b/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py index b9da20ec65..50789f0dae 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py @@ -76,7 +76,11 @@ class Usecase: ifcopenshell.api.run("grid.remove_grid_axis", self.file, axis=axis) # TODO: remove object placement and other relationships - for inverse in self.file.get_inverse(self.settings["product"]): + + # Use a while loop so that we don't keep inverses in memory that might + # get deleted as a result of the API calls in the loop body (#2697) + while inverses := self.file.get_inverse(self.settings["product"]): + inverse = next(iter(inverses)) if inverse.is_a("IfcRelDefinesByProperties"): ifcopenshell.api.run( "pset.remove_pset",