简体   繁体   中英

(When) Does the Xamarin.iOS garbage collector stop the whole application?

The Xamarin Cross-Platform Performance Documentation states:

When SGen starts a garbage collection, it will stop the application's threads while it reclaims memory.

I'm wondering about a few details:

  • I very much assume this applies to Xamarin.iOS? Is this correct?
  • Does this apply to the whole application? That is, also the unmanaged side?
    • Is the native ui thread stopped as well?
    • Are unmanaged threads stopped as well? Eg threads created by a native library which is wrapped via P/Invoke?
  • Do all collections (minor and major) stop the threads? Or does this only apply to major collections?
  • Just in case: Has the behaviour changed in the last year?

The standard caveat applies that you should profile to see how this plays out in your case, but here are some answers:

  1. This certainly applies to Xamarin.iOS.
  2. Yes, this will block the UI thread.
  3. I would guess that 'pure unmanaged' background threads, ie launched from native libraries and not referring to any managed code, wouldn't be blocked, but that's a guess.
  4. Minor collections will also block, but typically for a much shorter time.

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

Traditionally, when Mono's memory manager determined that it should perform a garbage collection, the collector had to pause all Mono running threads, perform the garbage collection, and once it was done, it resumed the execution of those threads.

With concurrent garbage collection, we are able to perform collections on the old generation (what we call major collections) mostly concurrently with your application - it happens at the same time as your program is running. When the major collection is completed, the collector only needs to pause the Mono threads for a very brief period of time at the end.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM