Native thread behavior during garbage collection

When the runtime starts garbage collection, it pauses all managed threads. My application has both managed and unmanaged components. There is a possibility that a native thread from unmanaged code might enter managed code when the runtime performs garbage collection.

How does .net work? Will .net pause its own thread or is something else going on?

+3
source share
1 answer

As I understand it, the reason why managed threads are paused is because the managed heap can be compacted during collection. If this happens, references to managed objects should be adjusted. I believe that your own threads do not use objects in the managed heap and therefore should not depend on garbage collection.

If your own threads have access to managed objects, you must migrate them. This will prevent the GC from moving during compaction.

+4
source

Source: https://habr.com/ru/post/1762578/


All Articles