27.6 C
New York
Friday, June 6, 2025

Reserved Reminiscence Hold Growing When Loading the Similar GameObject Utilizing Unity Addressables


I am attempting to learn to use Addressables in Unity to enhance reminiscence utilization, however there’s one thing I do not perceive.

I exploit the Graphy device to investigate reminiscence utilization.

Once I load a GameObject, each Reserved and Allotted reminiscence improve. Once I name Launch, solely the Allotted reminiscence decreases — which is predicted and I perceive that.


In the beginning of the sport, earlier than loading the GameObject.

After I load the GameObject
After I load the GameObject.

After releasing the GameObject
After releasing the GameObject.

What I do not perceive is that with each load operation, Reserved reminiscence retains rising, regardless that Allotted reminiscence stays the identical after Launch. Which means that throughout every load, Reserved reminiscence grows and by no means stops rising. Why does this occur? I am loading the identical GameObject each time, so should not the reminiscence have already been expanded the primary time? There should not be a have to develop it once more, particularly since I am certain the GameObject is being absolutely launched.

After many load and release operations of the GameObject, the Reserved memory reached 318 MB.

After many load and launch operations of the GameObject, the Reserved reminiscence reached 318 MB.

After releasing the GameObject, the Reserved memory size was 310 MB, with relatively stable Allocated memory size since the start of the game after the release operation.

After releasing the GameObject, the Reserved reminiscence dimension was 310 MB, with comparatively steady Allotted reminiscence dimension for the reason that begin of the sport after the discharge operation.

The code:

utilizing UnityEngine;
utilizing UnityEngine.AddressableAssets;

public class AddressablesManager : MonoBehaviour
{
    [SerializeField] personal AssetReferenceGameObject assetReferenceGameObject;
    personal GameObject spawnedGameObject;

    // Replace is known as as soon as per body
    void Replace()
    {
        if (Enter.GetKeyDown(KeyCode.D))
        {
            Load();
        }

        if (Enter.GetKeyDown(KeyCode.R))
        {
            Launch();
        }
    }

    void Load()
    {
        assetReferenceGameObject.InstantiateAsync().Accomplished += (asyncOperation) => spawnedGameObject = asyncOperation.Outcome;
    }

    void Launch()
    {
        assetReferenceGameObject.ReleaseInstance(spawnedGameObject);
        spawnedGameObject = null;
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles