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.
1 Like
Bust out the profiler (Window → Analysis → Profiler) and see where things are going.
With something that large it should be fairly easy to spot.
Are you testing in a build?
Memory management in the editor works differently and isn’t indicative of its behaviour in a build.
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.
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.
1 Like