Thursday, June 5, 2025
HomeGame DevelopmentReserved Reminiscence Maintain Rising When Loading the Identical GameObject Utilizing Unity Addressables

Reserved Reminiscence Maintain Rising When Loading the Identical GameObject Utilizing Unity Addressables


I am making an attempt 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.

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

Reserved Reminiscence Maintain Rising When Loading the Identical GameObject Utilizing Unity Addressables
At first 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 growing, although Allotted reminiscence stays the identical after Launch. Because of this throughout every load, Reserved reminiscence grows and by no means stops growing. 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 must broaden it once more, particularly since I am positive 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 named 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.Consequence;
    }

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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments