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.
At first of the sport, earlier than loading 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 launch operations of the GameObject, the Reserved reminiscence reached 318 MB.
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;
}
}