Out of memory after rendering thousands of similar scenes
In case anyone have a similar problem, I figured out the solution.
My script was generating a new texture at each iteration. I thought it was being discarded but actually not, blender was retaining this information as orphan data. So I simply needed to add bpy.ops.outliner.orphans_purge() at each iteration to clean this unused data that was loading my memory.