(When) Does the Xamarin.iOS garbage collector collect the entire application?

The Xamarin Cross-Platform Performance Documentation says:

When SGen starts garbage collection, it stops application threads while it reclaims memory.

I'm interested in a few details:

  • I highly believe this is specific to Xamarin.iOS? Is it correct?
  • Does this apply to the entire application? That is, the uncontrollable side?
    • Couldn't the ui native thread stop as well?
    • Are the unmanaged threads stopped as well? For example. threads spawned by built-in library wrapped via P / Invoke?
  • Do all collections (small and large) stop streams? Or does this only apply to the main collections?
  • Just in case: has the behavior changed in the past year?
+3


source to share


1 answer


The standard caveat applies to the fact that you need a profile to see how this happens in your case, but here are some answers:

  • This is certainly the case for Xamarin.iOS.
  • Yes, this will block the UI thread.
  • I would assume that "pure unmanaged" background streams, i.e. launched from native libraries and not related to any managed code will not be blocked, but this is an assumption.
  • Minor collections will also be blocked, but usually for a much shorter time.

And finally, yes, this has changed significantly recently with the addition of concurrent garbage collection :



Traditionally, when the Monos memory manager determined that it should perform garbage collection, the collector had to suspend all Mono threads from starting, garbage collect, and once that was done, it resumed execution of those threads.

With concurrent garbage collection, we can run old generation collections (what we call large collections) mostly concurrently with your application — this happens when your program is running. When the main collection is complete, the collector only needs to temporarily suspend the Mono threads at the end.

Parallel GC is available as a build option in the current stable release of Xamarin (see link for details ).

+1


source







All Articles