I don’t think it would be caused by itertools, but you could try to isolate the root cause of the increased memory usage by removing it as well as other parts of the code until the memory increase disappears.