Cause and mechanism
Preview Textures and Materials created by an EditorWindow use Unity-side resources as well as C# references. If memory keeps increasing after opening and closing the window, compare creation and destruction. Setting a reference to null is not cleanup by itself; destroy resources owned by the window at the appropriate time.
Check and correct the setup
- Distinguish owned temporary objects from shared project assets.
Release / Dispose - Use idempotent cleanup for owned editor resources; never destroy shared assets.
Release / Dispose - Unsubscribe editor events and dispose preview helpers/targets according to ownership.
Release / Dispose
Limits and verification
OnDisable is not exclusively a close event. Test reenabling/recompilation and compare retained resources.
A focused diagnostic setup
Repeat opening/closing and count owned preview textures/materials. Separate Editor caching from resources retained by this window.
Test in this order
- Pair creation with cleanup and distinguish temporary ownership from shared assets.
Release / Dispose - Make cleanup safe across close, re-enable and recompilation.
Release / Dispose - Verify event unsubscription and preview disposal, comparing object counts across cycles.
Release / Dispose
Interpret the result
Continuing callbacks suggest subscriptions; increasing native-object counts suggest disposal gaps. Immediate process-memory return is not the only criterion: inspect repeated retention of owned resources.