Re: [Rubydotnet-developer] GC ideas
Status: Alpha
Brought to you by:
thomas
From: Tim S. <ti...@ih...> - 2004-01-13 01:10:35
|
On Mon, Jan 12, 2004 at 01:32:58PM +0100, Thomas Sondergaard wrote: > I don't really understand how reference counting is error prone? Speaking > for my own implementation I use a System.Runtime.InteropServices.GCHandle in > the ruby-proxy-object to keep the .net object reference. The GCHandle > mechanism is a reference counting scheme for referencing .net objects > outside of the .net runtime. Similary, I use rb_gc_register_address in > the .net-proxy constructor to tell ruby that there is an external reference > to that object. I don't see any significant potential for forgetting to > update the reference count, the major problem is the circular references > problem. [...] Okay, I was exaggerating :) Reference counting was working perfectly well for me too. The hard part is avoiding race conditions with the garbage collector(s) [System.GC.KeepAlive etc.], and my idea doesn't help with this. However, when I was using reference counting I had (for Ruby calling .NET) about 7 C# methods which would increase a reference count and return an OBJ. It was assumed that the C code would store this in a struct DotNetData and decrease the reference count when freed. I didn't like that these methods depended on their callers to do the right thing. -- The pigeonhole principle: If you have N pigeons and drill at least N + 1 holes in them, you will have at least one pigeon with at least two holes in it. |