Untracked memory is being impossible to fix and is delaying console release

For around a year now I’ve been trying to figure out why untracked memory is so high (fixing the memory that I can track was quite straight forward), the last time after almost a month trying to fix it I just gave up, nothing I tried worked and no suggested fix did anything to help, now with the Switch release upon us I cannot ignore it anymore, but after a whole week fighting it I’m out of options, this is what happens:

The game loads, the memory is around 500mb in the main menu (good)
We load an game scene, the memory goes up to 700mb or so (good)
Now if we go back to the main menu, or any other scene the memory goes to 1.4gb (not good)

the increase is mostly around untracked memory that goes up to around 0.7gb or so, which means I cannot see what is causing it, but what concerns me is that even if I load a completely empty scene multiple times with absolutely nothing on it, the untracked memory is still 0.7GB, in that completely empty scene I added one script with the following code:

using System;
using UnityEngine;

public class ClearMemoryEmptyScene : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Resources.UnloadUnusedAssets();
        GC.Collect();
    }
}

the scene is completely empty, but that resolves nothing, all I want at this point is to tell Unity to please, clear anything it may have, start again, be one with the void and load the next scene fresh.

  • I tried to clear all Addressables.
  • Made sure that any static in the previous scene is null ondestroy and ondisable
  • Destroyed every gameobject of the scene
  • Used Resources.UnloadUnusedAssets(); on the new scenes
  • Used GC.Collect(); in the new scenes
  • Emptied the Resource folder

This is driving me to insanity and it is the last thing I need to deal with for what would be a smooth console release, but Unity won’t budge, anyone has any suggestion?

screenshots of the exact same scene being reloaded from itself

Any updates?

We focused on trying to solve the memory that we can handle, and apply best practises where we could, and hope for the best, we managed to get the memory to a level where it would not crash, but it could be way better, what I learned from this is to regularly check the memory during development and handle untracked memory ASAP as soon as something spikes, because if you wait until too late you will end up with a messy memory that looks impossible to handle.

^ ^ ^ This really is the key to everything, especially for console and mobile targets:

Test regularly on the targets you really care about.

You will run out of memory or performance far sooner on those targets than on your super-smokin’ hot crazy turbo $5000 desktop gaming rig where you decided to try some game development. :slight_smile:

For all performance and optimization issues, ALWAYS start by using the Profiler window:

Window → Analysis → Profiler

1 Like