My Xamarin app on Android creates approx. 30 new references every second (I guess one reference occupy approx. 100 bytes - but this is not important). I create these objects intentionally and they should live throughout the lifetime of the application.
I can see more frequently this in log output as my application runs for longer time:
04-11 16:46:22.658 D/Mono (14892): GC_BRIDGE waiting for bridge processing to finish
04-11 16:46:22.661 D/Mono (14892): GC_TAR_BRIDGE bridges 424 objects 2303 colors 445 ignored 814 sccs 424 xref 150 cache 0/0 setup 0.16ms tarjan 2.39ms scc-setup 0.20ms gather-xref 0.06ms xref-setup 0.02ms cleanup 0.31ms
04-11 16:46:22.661 D/Mono (14892): GC_BRIDGE: Complete, was running for 49.28ms
04-11 16:46:22.661 D/Mono (14892): GC_MAJOR: (LOS overflow) time 27.89ms, stw 29.64ms los size: 2048K in use: 467K
04-11 16:46:22.661 D/Mono (14892): GC_MAJOR_SWEEP: major size: 3936K in use: 2558K
After an hour my application runs the frequency is 1 per second.
The consequence is I can see lags in my application (as the GC takes several tens of miliseconds).
Is there anything I can do with this issue?
using
android:largeHeap="true"
In the manifest on the application tag tells the system that your app needs extra RAM(aka "heap"). The garbage collection is run because you are using a lot of memory - and because the max memory is limited by the system you need to request extra memory. YOu can't declare that your app needs x MB, the system gives you RAM automatically - declaring largeHeap ensures that your app gets enough memory to handle all your objects. And it is automatically scaled. One of my apps crashed because it was allocated 10 MB or so of ram (and that is a lot based on the default of my device). After I declared largeHeap, it uses about 30 MB of ram(on average) and doesn't crash. If it needs more, Android allocates more after a garbage collection event
In my case it was the ListView CachingStrategy option set to CachingStrategy="RecycleElement"
causing the same GC issues as described on android only in debug mode.
Removing this and using the default solved the GC problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With