Search Unity

Memory not decreasing after changing scenes

Discussion in 'Scripting' started by FG_dev1, Feb 22, 2017.

  1. FG_dev1

    FG_dev1

    Joined:
    Nov 3, 2014
    Posts:
    44
    We seem to have a bunch of memory that's not being freed up when loading new scenes. The current loading process is start in 1 level, use a singleton loading screen to load into an empty scene then call System.GC.Collect(); and Resources.UnloadUnusedAssets(); (just in case) then load the next level. But levels only ever make the memory increase in size, even when reloading the existing scene, memory only goes up.

    Here is a brief overview of what happens:

    - Loading into the HUB Area starts at around 590,000K (according to task manager memory usage). This seems ok as it's a 3D walk around area
    - after transitioning to an empty scene (via the above) still has the program at 405,000K
    - after starting the first actual level memory is at 840,000K
    - after loading back into the empty scene again the memory is at 750,000K
    - after starting a new level (level 2) it jumps to 1,195,000K
    - after loading back into the empty scene as above the memory is at 1,010,000K
    - then going back to the HUB world at the stat (via loading transition above) the memory is at 1,227,000K

    I don't think this is a unity asset leak because I've goth through to clear up procedural meshes/materials and in the empty loading screen I looked up what UnityObjects existed and it only had this (after the above process):



    The memory snapshot at this point looks like this



    I don't know if they are the problem or if it's an editor thing but is there anyway to track down what is creating the render textures?

    One thing we've found is loading into a boss level then going back to the HUB area actually decreases memory like it should (was around 800MB after going from the Boss -> HUB area). But I'm not sure why that triggers the memory getting cleared.

    Currently on Unity 5.5.0f3

    If anyone has any ideas on why this is happening or could help it would be really appreciated.

    Thanks
     
    Last edited: Feb 22, 2017
  2. FG_dev1

    FG_dev1

    Joined:
    Nov 3, 2014
    Posts:
    44