I am developing for iOS, so I want to have as few spikes as possible…
I see that I am growing my allocated heap at a rate of a few K every few seconds. I cannot at this stage determine why this is. The MAX heap size is tiny also, I have around 500K of headroom before a collect will occur.
Following the advice I had read in the Unity docs on maintaining performance I added a GC.Collect() every 30th frame. However this seems to take a huge amount of time, like 60MS every single time I issue a collect (iPhone 3G S) and there’s typically only a few K to actually collect. I was rather expecting more in the region of the 5MS suggested.
I am enabling ENABLE INTERNAL PROFILER to see these numbers.
Is this because we have a big app (maybe 50MB) and so we have a small heap size and a lot of RAM to check over during a collect?
Has anyone else experienced this?
Also, I have assumed that the heap sizes are in bytes, could anyone confirm this?
Sorry for the late reply, but the question is still relevant.
Unity3D has been using the same GC technology since it was first created. Since then there have been two generations of GC technology. However, due to licensing issues Unity3D chose not to update this, despite hordes of gamers and developers saying they should.
There are ways to reduce the problem though, see the other reply for your best bet there.
That’s the bad news, and is why this has been such a major problem for Unity developers.
Fortunately, though, those licensing issues have finally been resolved and according to the dev blog, Unity is going to be moving to a new GC model in future revisions. There are still some binary backend hooks to work out, and some things related to optimization and profiling, as Unity has become quite dependent on the old GC system.
Without getting into detail, the new GC system will have far shorter world-stops and main-thread stops, and that will reduce problems drastically. However, it is still a very good idea to optimize for GC handling in interactive games.