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?
Okay, so I'll answer my own question here, sorry it's probably obvious but hopefully will help someone else:
See the docs here:
It's slow because as mentioned in this video...
...the whole heap has to be considered and as my heap is not 200K but 3.5MB it's like 10 times the cost.
It seems calling Collect() is best done between level loads and obviously it's best to avoid this full stop.
answered Dec 23 '11 at 02:19 PM