The public interface of the Mono GC is fairly limited, and
its the only one that embedders should be using:
mono_gc_reference_queue_new
Syntax
MonoReferenceQueue*
mono_gc_reference_queue_new (mono_reference_queue_callback callback)
Parameters
callback | callback used when processing collected entries. |
Return value
the new queue.
Description
Create a new reference queue used to process collected objects.
A reference queue let you add a pair of (managed object, user data)
using the
mono_gc_reference_queue_add
method.
Once the managed object is collected
callback will be called
in the finalizer thread with 'user data' as argument.
The callback is called from the finalizer thread without any locks held.
When an AppDomain is unloaded, all callbacks for objects belonging to it
will be invoked.
SGen Bridge
The bridge is a mechanism for SGen to let clients override
the death of some unreachable objects. We use it in monodroid
to do garbage collection across the Mono and Java heaps.
The client can designate some objects as "bridged", which
means that they participate in the bridge processing step once
SGen considers them unreachable, i.e., dead. Bridged objects
must be registered for finalization.
When SGen is done marking, it puts together a list of all
dead bridged objects and then does a strongly connected
component analysis over their object graph. That graph will
usually contain non-bridged objects, too.
The output of the SCC analysis is passed to the
`cross_references()` callback. It is expected to set the
`is_alive` flag on those strongly connected components that it
wishes to be kept alive. The value of `is_alive` will be
ignored on any SCCs which lack bridges.
In monodroid each bridged object has a corresponding Java
mirror object. In the bridge callback it reifies the Mono
object graph in the Java heap so that the full, combined
object graph is now instantiated on the Java side. Then it
triggers a Java GC, waits for it to finish, and checks which
of the Java mirror objects are still alive. For those it sets
the `is_alive` flag and returns from the callback.
The SCC analysis is done while the world is stopped, but
the callback is made with the world running again. Weak links
to bridged objects and other objects reachable from them are
kept until the callback returns, at which point all links to
bridged objects that don't have `is_alive` set are nulled.
Note that weak links to non-bridged objects reachable from
bridged objects are not nulled. This might be considered a
bug.