I’m developing a multi-user application. I’ve noticed that when new users connect to a room (I’m using Photon, if that information might be helpful), the model of the connected player appears in the room.
I’m facing RAM consumption issues. Moreover, I don’t understand what exactly occupies this memory. Below, I am attaching a screenshot of the snapshots.
The first snapshot (A) was taken when the player was alone in the room.
The second snapshot (B) was taken after other users connected to the player’s room and then disconnected.
As you can see, the difference is 1.16 GB, while nothing from the section (Top Unity Object Categories) has increased.
Uh, that’s kinda odd, the only thing that really seems to have happened is that a good chunk more of your existing allocations became resident, touched by the program and loaded from secondary memory (Swap, Compressed, Mapped from disk) into RAM. Like you’ve touched and modified all art assets (are they read/write enabled?) or similar. Annoyingly the only way to find out more would be to Profile this on builds of 2023.1+ Unity versions, where we have detailed info on what objects/ memory pages are Resident. There it should be visible in the All Of Memory page.
The only other alternative would be to use a native platform profiler.
That depends on the details of your platform (Platform, CPU, GPU) but there’s a list of them here. Basically one that’s specifically for an OS and/or set up hardware componentes
I installed version 2023.2.6f, and now I’m seeing really strange things:
Now according to the profiler, memory consumption does not increase as much as can be seen from the previous (above) screenshot. There is an increase of only 50 MB (and most of this is due to the profiler, as far as I understand).
So my question is, can the RAM in a build grow depending on what version of unity the project was built with? This sounds very strange, but that’s exactly what my first thought is.
In the old snapshot opened in the unity 2023+ version, unfortunately there is no additional information. This is because the snapshot was made in a previous version of Unity, right?
yeah that’s totally possible. I’d hope that’s due to a bugfix that might still be getting backported but that’s not necessarily the case. Hard to tell.
And yes, that looks like it’s mostly the Profiler. Btw, that would the frame data for the Profiler Window. You can disable that profiler while memory Profiling to forgo that memory growth, though obviously then it gets a bit harder to know when to take the next snapshot.
Yep, the base Unity version the snapshot comes from determines the data. The package version determines how and what of the data gets read and how it’s prepared for you to analyze. The version you take the snapshot with or open it in doesn’t matter.
Thank ya for the post update and also for the blog post.
Unfortunately I still have this problem on Android and Windows platforms. And I still really don’t understand how to catch this memory leak.
As I already wrote above in the post, the application I am working with is a network one.
With each new player connecting, I see a non-linear increase in memory in the app of the already connected player. And the memory profiler still doesn’t provide detailed information about why this happens.
Well, thanks for the help. I continue to search for the source of the problem.
The problem was the many textures of player models loaded at runtime. Each texture was 16 MB in size (base color, metallicity map). Thus, almost every subsequent player took up 312+ MB. That there are a lot of Android devices.
I compressed the textures at runtime using Texture2d.Compress() and now the problem is solved.
Now about why this was not visible in the profiler:
I used the profiler on Windows builds, and not on the target Android device. Therefore, the results obtained did not show the real state of affairs. To everyone who sees this thread: use the profiler directly on the target device, this way you will get more relevant information, since memory allocation can work differently on different platforms and this can play a cruel joke on you.