Memory optimisation with del and gc.collect