Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

Loadable<T0>.Release

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public void Release();

Description

Releases the loaded object so that Unity can unload it.

Unity reference counts the loaded object, so loading the same asset through several Loadable<T0> instances works correctly, and the object unloads only when the last reference is released.

Each Loadable<T0> instance holds at most one reference. Repeated Loadable<T0>.Load or Loadable<T0>.LoadAsync calls on the same instance return the same load operation without taking another reference, so a single Release frees it and any further Release does nothing. Release every instance that you loaded, otherwise the object stays loaded after your code stops using it.

Release is not recursive. If this Loadable references a ScriptableObject that has loaded Loadable<T0> fields of its own, releasing this Loadable does not release those inner ones. Release each Loadable<T0> that was loaded.

The OnDestroy message of a MonoBehaviour is a good place to release its Loadable<T0> fields, so that unloading a scene or destroying a prefab instance does not leave content loaded that nothing can reach.

Release has no effect on content that was loaded from the AssetDatabase in Play mode, because that content is not reference counted. Refer to the Loadable<T0> remarks for details.