If I had a reference to a ScriptableObject
- I then set that to null
so nobody’s referencing the SO anymore. Will unity destroy the SO for me? or do I have to Destroy it before setting the reference to null?
Thanks.
If I had a reference to a ScriptableObject
- I then set that to null
so nobody’s referencing the SO anymore. Will unity destroy the SO for me? or do I have to Destroy it before setting the reference to null?
Thanks.
You have to destroy a ScriptableObject you create - presuming that it isn’t added as an asset to the system - if you want to free up the memory during execution.
Unreferenced ScriptableObjects are trashed when the editor recompiles so it is less likely to cause a big leak in an Editor script.
Bit late to the party ^^, but I had the same question and found that when a ScriptableObject has no references the OnDisable method will be called when there is a scene change (the ScriptableObject will go out of scope ). After a while the ScriptableObject get’s GC’d but OnDestroy is never called.