Figure: Diagnostic workflow: Owned temporary resources → Lifecycle cleanup → Protect shared assets
Figure: Diagnostic workflow: Owned temporary resources → Lifecycle cleanup → Protect shared assets

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

  1. Distinguish owned temporary objects from shared project assets.
    Release / Dispose
    Release / Dispose
  2. Use idempotent cleanup for owned editor resources; never destroy shared assets.
    Release / Dispose
    Release / Dispose
  3. Unsubscribe editor events and dispose preview helpers/targets according to ownership.
    Release / Dispose
    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

  1. Pair creation with cleanup and distinguish temporary ownership from shared assets.
    Release / Dispose
    Release / Dispose
  2. Make cleanup safe across close, re-enable and recompilation.
    Release / Dispose
    Release / Dispose
  3. Verify event unsubscription and preview disposal, comparing object counts across cycles.
    Release / Dispose
    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.

Related explanations

References