When disappearing links are collected before their targets
Jim Pryor <[email protected]>
| Newsgroups | gmane.comp.programming.garbage-collection.boehmgc |
|---|---|
| Message-ID | <[email protected]> |
I'm just starting to work with the Boehm GC library, and am trying to add weakref functionality to a project that already uses the main functions of the library (including finalizers). I think I've got a basic understanding of how GC_general_register_disappearing_link and nearby functions work. However, I wasn't able to tell from the comments or other documentation what is the answer to this question: If I create a disappearing link L to another object O, but then L ends up being collected before O does, when the time comes around for O to be collected, we obviously don't in that case want L to still be cleared. So do I have to manually create a finalizer for L to GC_unregister_disappearing_link it before it gets collected? Or does the library take care of this automatically. Looking at the source (finalizer.c): I haven't fully digested everything here yet, but superficially at least it looks like the answer to my question is that the library takes care of this automatically, when it invokes the function GC_remove_dangling_disappearing_links. I'm writing the list for two reasons: (1) to invite others to correct me if I've misunderstood, and (2) to make this question and answer available to others who might search for it. (I wasn't able to find any explicit discussion of this in my own searches.) Perhaps (3) it'd be good to add a sentence or two to the comments in gc.h (or finalize.c) declaring explicitly that this is the designed behavior, and that one doesn't need to manually unregister weakrefs on one's own, just before they're collected. -- [email protected]