title: Blender freezes between renders
body: <p>I'm currently working with blender 3.0 and i got a problem running some renders (this also happen with blender 2.93).<br>
  My team has a scene where we spawn some objects (40-50) via python (they are duplicates of objects in a certain collection), we then render and save it into a file. After each render we run some cleanup code to avoid memory problems (we need around 10k renders). To execute the cleanup code and prepare for the next render it takes around 0.05s at the beginning but after 1.5/2k renders it takes more than 5mins (as the number of renders done increases we get a longer freeze between the current and the next render). Restarting blender 'reset the freeze duration' to 0s.<br>
  The overall code looks like:</p>
  <pre><code>for idx in range(number_of_renders):
      camera.location = Vector(random, random, random)
      camera_target.location = Vector(random, random, random)
      ... # randomly set hide_viewport and hide_render to true/false to change overall brightness of all lights
      spawned_objects = populate_scene(settings)
      bpy.ops.render.render(write_still=True)
      metrics = generate_metrics(settings) # generate some metrics about facing objects
      save_metrics(metrics) # save the metrics in a .txt file
      cleanup(spawned_objects)
  </code></pre>
  <p>Code we use to create the duplicates:</p>
  <pre><code>templates = [template.name for template in bpy.data.collections.get(&quot;Templates&quot;).objects]
  ... # set random image to all templates textures
  source_object = bpy.data.objects[random.choice(templates)] # get a random object from templates
  product = source_object.copy()
  product.data = source_object.data.copy()
  product.location.x/y/z = ...
  spawned_objects.append(product)
  if facing_object: # if it is a facing object we add it into the facing collection (we measure some metrics later on)
      facing_collection.objects.link(product)
  else:
      background_collection.objects.link(product)
  </code></pre>
  <p>Code we are using to clean the spawned objects:<br></p>
  <pre><code>def cleanup(spawned_objects):
      # Deselect all eventually selected objects
      bpy.ops.object.select_all(action='DESELECT')
  
      # Select only the spawned objects
      for obj in spawned_objects:
          obj.select_set(True)
  
      # Delete spawned objects
      bpy.ops.object.delete()
  
      # Cleanup
      for block in bpy.data.meshes:
          if block.users == 0:
              bpy.data.meshes.remove(block)
  
      for block in bpy.data.materials:
          if block.users == 0:
              bpy.data.materials.remove(block)
  
      for block in bpy.data.textures:
          if block.users == 0:
              bpy.data.textures.remove(block)
  
      for block in bpy.data.images:
          if block.users == 0:
              bpy.data.images.remove(block)
  </code></pre>
  <p>We are currently 'solving' this problem by running 10 times the program, each time capped at 1k renders, we then join them together in a single directory. Any idea about why we get a freeze or why it become longer the more renders we make?</p>