Does anyone knows how unity/mono 's garbage collection on android? I would think that mono is living in its own world and thus doing its own GC since it is not compiled to java, but I’d like to have some other people’s thoughts on this…
I’m asking this because when my game runs on the nexus one, I have some frequent and very anoying DVM GCs like:
which basically kills the gameplay experience, since our game is an action game. Why are there so many frequent DVM gc if unity/mono is running and managing its own memory?
I hope this can be fixed, otherwise I don’t know if our game can be viable on the android market having such big issues… x_x’
If you have frequent GC’s, you should look through all the posts about optimizing your code to avoid unnecessary allocations. Since iPhone users have been dealing with this for a while, there’s plenty on the forums about it. It mostly involves caching references from convenience properties on a lot of built-in objects. Good luck!
The frequent GC’s are not the Mono GC, but the Galvik VM’s garbage collections. I have tracked mono’s gcs through the unity profiler data (available with logcat) and there is not correspondance with them.
Mono’s GC happens at seldom intervals and dont take more than 10 ms, while GVM’s GC happens very often (about once per 1.5 secs) and last more than 40ms!
These pauses are killing the gameplay of our game, so it is a show stopper for us…
Anyone else developping on Android seeing these GCs? Do they happen also often and take about the same collection time?
Hmm, these heavy GC spikes were related to the usage of the player prefs! Fortunately, android saves the state of an app when you quit it, so I could just flush away my game persistence code and avoid them!
Still I wonder how calls to PlayerPrefs could generate do many GVM GC calls… x_x’
If you used them the wrong way (like accessing them the whole time to missuse them as “datacontainer”) its no wonder. You should restrict playerprefs usage to what its name implies: preferences
not as a freeform datacontainer, using System.IO.File and BinaryFormatter for example is a much more convenient (and hell more performant way) to do so, when used in combination with a Hashtable for example.
The GC spiking you likely see there comes from the behavior of most (I think nearly all but Galaxy S if we go by out of the box benchmark results) android devices that use the RAM as intermediate system memory storage, yet if you create, remove, create, remove a file over and over again (what write access to playerprefs does in the end) it means that you have countless full playerpref sized memory garbage blocks that android has to get rid of …
As PlayerPrefs is backed by a Java object (because everything relating to Android OS is Java) you will get GC calls from interacting with that Java object.