Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Release unused LocalizedAssets

Discussion in 'Localization Tools' started by AzurySimon, Jan 21, 2021.

  1. AzurySimon

    AzurySimon

    Joined:
    Jul 16, 2018
    Posts:
    38
    Hi,

    I am trying to release unused localized assets from memory in my appplication. Once loaded the asset would remain in memory (according to the Addressables Event Viewer), even when not in use.

    I tried releasing the CurrentLoadingOperation of my LocalizedAsset instance, but it did not release the asset (Addr Event Viewer). Doing this did not seem to make any difference.

    I also tried to keep a reference to the handle returned by LoadAssetAsync (on LocalizedAsset) and releasing this handle later on. This released the asset in the Event Viewer, but this also resulted in an Exception ("invalid operation handle") when I tried to load the same asset again.

    Is there an official way to release unused localized assets from memory?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,222
    Hi,
    At the moment the AssetTable holds an internal AsyncOperation for each asset that has been requested previously.
    We have added a ReleaseAssets method in the next release but this will release all the AsyncOperations in the table, not just a chosen 1.
    It should be simple for us to add it. Ill add it to out tasks.
    If you want to do it now you can change the AssetTable.cs file and make line 15 public instead of internal
    Code (csharp):
    1. internal AsyncOperationHandle? AsyncOperation { get; set; }
    Now just get the entry from the table, if the operation is not null then release it and finally set it null so that it will be fetched correctly if you request it again in the future.