[gclist] Releasing symbols and sharing objects
Thu, 16 Nov 2000 19:19:54 +1100
On 15-Nov-2000, Ken MacLeod <email@example.com> wrote:
> I have two situations that I'd like to hear how people handle them.
> I'm using Boehm GC in C.
> First, I have a symbol (or flyweight) table where I keep "one" copy of
> each symbol as they are used or created. Over time, most of the
> symbols will be not referenced by any objects, except for the symbol
> table itself. How can I recognize this and free those symbols?
The usual suggestion in this case is to use weak pointers in the
To free the space occupied in the symbol table itself,
you can either clean it up while you're traversing the
symbol table, or use finalizers.
I'm not sure which works out better in practice.
> Second, I am interfacing my code in C with Perl (and eventually Python
> and other languages) and sharing objects between the two runtimes. My
> current plan is to maintain a list of "Perl has a copy" pointer
> references (to prevent them being released otherwise), and delete
> these references when Perl deletes the Perl object. Anybody have
> experience with that, and does it work well?
With the Boehm GC, another approach is to just use
`-DREDIRECT_MALLOC=GC_malloc_uncollectible', so that the conservative
collector scans the memory owned by other code (e.g. Perl).
This is a lot simpler, but not as portable.
Fergus Henderson <firstname.lastname@example.org> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.