I found a lot of solutions for deleting unused data. Most of them are not practical for my case.
I have a very long script and during this, I want to purge all the unused data from the memory.
I'm trying to run this script but I keep getting errors:
import bpy bpy.types.SpaceOutliner.display_mode = "ORPHAN_DATA" bpy.ops.outliner.orphans_purge()
RuntimeError: Operator bpy.ops.outliner.orphans_purge.poll() failed, context is incorrect
Note: I can't reload blender; it's a long and continuous operation and can't be interrupted and if I ignored purging data the memory will leak.