Lag issue with canvas game and garbage collection

LarsJarlvikLarsJarlvik Lars JarlvikSEMember
edited September 2014 in Xamarin.Android

Hello

I have made an app with a small "bouncing ball" game using Androids canvas. The problem is that the game works fine and smooth except when the garbage collector kicks in which makes the game lag for a short while.

This happens about every fifth second and I get the following message when debugging:

[Mono] GC_MINOR: (Nursery full) pause 30.52ms, total 30.68ms, bridge 41.16ms promoted 912K major 1168K los 369K

I tried to increase the garbage collection size after reading other posts but without effect. I'm actually not sure if it kicked in at all. However I guess increasing the size just make the lag appear less often but it will be worse when it does?

Is there any good way to avoid this?

Thanks
// Lasse

Posts

  • CheesebaronCheesebaron Tomasz Cielecki DKInsider, University mod

    Avoid creating new objects on every Draw call, reuse as many objects as possible. So all the Paints, Drawables etc. should only be created once and then overwritten if needed. This might keep the collections to a minimum.

Sign In or Register to comment.