From b02f9ac6bb7e732b3e0795f8a91e600da159eecc Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Mon, 7 May 2012 11:31:22 -0300 Subject: [PATCH] When cleaning up the finalizers of a domain, do it in a way that reduces the chance of leftover objects. * gc.c (finalize_domain_objects): When cleaning up a domain, we run two kinds of finalizers, those that have already been queued and those for objects that remain alive. A common problem we need to deal is that some finalizers allocate other finalizable objects when doing seeminly trivial operations such as String.IndexOf - which might require the Thread object of the finalizer thread to be instantiated. We handle those new objects by draining the registered finalizers set until none shows up. This fails if we run the queued finalizers after that. The order onto which finalizers are run on domain unload is unspecified and the new behavior can be argued to be more natural. --- mono/metadata/gc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mono/metadata/gc.c b/mono/metadata/gc.c index d47e39a07cd..409124fe1fa 100644 --- a/mono/metadata/gc.c +++ b/mono/metadata/gc.c @@ -1005,6 +1005,9 @@ finalize_domain_objects (DomainFinalizationReq *req) { MonoDomain *domain = req->domain; + /* Process finalizers which are already in the queue */ + mono_gc_invoke_finalizers (); + #ifdef HAVE_BOEHM_GC while (g_hash_table_size (domain->finalizable_objects_hash) > 0) { int i; @@ -1038,9 +1041,6 @@ finalize_domain_objects (DomainFinalizationReq *req) } #endif - /* Process finalizers which are already in the queue */ - mono_gc_invoke_finalizers (); - /* cleanup the reference queue */ reference_queue_clear_for_domain (domain); -- 2.11.4.GIT