Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

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

Discussion in 'Editor & General Support' started by dr4, Apr 11, 2024.

  1. dr4

    dr4

    Joined:
    Jan 14, 2015
    Posts:
    115
    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:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. public class ClearMemoryEmptyScene : MonoBehaviour
    5. {
    6.     // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.         Resources.UnloadUnusedAssets();
    10.         GC.Collect();
    11.     }
    12. }
    13.  
    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

    upload_2024-4-11_23-6-37.png

    upload_2024-4-11_23-7-10.png
     
  2. IgorGalimski-J

    IgorGalimski-J

    Joined:
    Apr 1, 2024
    Posts:
    7
    Any updates?
     
  3. dr4

    dr4

    Joined:
    Jan 14, 2015
    Posts:
    115
    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.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,356
    ^ ^ ^ 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. :)


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

    Window -> Analysis -> Profiler
     
    MartinTilo likes this.