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

Discussion RAM usage increases after changing scenes.

Discussion in 'Editor & General Support' started by romanstasyshyn, Sep 25, 2023.

  1. romanstasyshyn

    romanstasyshyn

    Joined:
    Jul 20, 2017
    Posts:
    6
    RAM usage increases after changing scenes.
    I have two scenes. The first scene is the main menu and the second scene is the first level of the game.
    The first scene takes 250 mb of RAM. The second scene takes 3000 mb of RAM.

    I have two problems.
    Problem 1.
    When I go from the second scene to the first scene, the first scene no longer occupies not 250 mb, but 1400 mb of RAM.
    This happens once when I first switch from the second scene to the first scene.

    Problem 2

    When I go from the second scene to the first scene, the first scene increases RAM usage by about 100 mb.
    This happens all the time when I go from the second scene to the first scene.

    I used "Resources.UnloadUnusedAssets" and it didn't help.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,102
    Bust out the profiler (Window -> Analysis -> Profiler) and see where things are going.

    With something that large it should be fairly easy to spot.
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,228
    Are you testing in a build?

    Memory management in the editor works differently and isn't indicative of its behaviour in a build.
     
  4. romanstasyshyn

    romanstasyshyn

    Joined:
    Jul 20, 2017
    Posts:
    6
    I ran all the tests in the build. First, I monitored RAM usage using Task Manager.Then I connected the profiler and noticed the growth of reserved memory when moving from one scene to another.
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,583
    There's also a specific Memory Profiler available as a packge (I think it's still in preview).
    I wouldn't call the added memory usage in the menu scene an issue. It could also be cached data since the next level will likely need it again.

    You should check if repeatedly loading the level and returning to the menu causes memory usage to increase every time indefinitely, in that case you have a memory leak.
     
    MartinTilo likes this.