Re: [MacRuby-devel] WeakRef advice

2011-02-18 Thread Charles Oliver Nutter
On Tue, Feb 15, 2011 at 5:28 PM, Laurent Sansonetti wrote: > Hi Alan, > Do you control the data structure that holds a reference to 'B'? If yes, you > may want to use NSHashTable which supports weak references. > To me, this sounds like a design problem. Maybe your project can be > re-architecture

Re: [MacRuby-devel] WeakRef advice

2011-02-18 Thread Charles Oliver Nutter
Another important use of weakrefs came to mind: avoiding finalization. In general, finalizers are a bad idea. They often block GC, or at least block each other. They add overhead to GC cycles, since either finalizers must be run or objects must be enqueued for another thread to run their finalizer

Re: [MacRuby-devel] WeakRef advice

2011-02-17 Thread Alan Skipp
Hi Laurent, Thanks for your suggestion - yes I do have control of the data structure, so I am able to implement it differently, I'll take a look at NSHashTable, I'll also consider if there is a way of avoiding this pattern. I've did a bit more research and there seems to be another more underlyi

Re: [MacRuby-devel] WeakRef advice

2011-02-15 Thread Laurent Sansonetti
Hi Alan, Do you control the data structure that holds a reference to 'B'? If yes, you may want to use NSHashTable which supports weak references. To me, this sounds like a design problem. Maybe your project can be re-architectured to avoid this pattern. Laurent On Feb 15, 2011, at 12:22 AM, A

Re: [MacRuby-devel] WeakRef advice

2011-02-15 Thread Alan Skipp
Hi Laurent, Thanks for the response. In essence the problem I have is something like this: Object 'A' is created, then to handle Key Value Observing, Object 'B' is created which holds an instance variable to Object 'A'. 'B' is held in a hash or array somewhere. Object 'B' only has a purpose whil

Re: [MacRuby-devel] WeakRef advice

2011-02-14 Thread Laurent Sansonetti
Hi Alan, MacRuby should have the same problem. ObjectSpace._id2ref in MacRuby basically maps an object pointer value to a numerical description, and the GC recycles objects. I am curious why you need weak references, though. MacRuby is able to detect and deal with reference cycles, so you sho

[MacRuby-devel] WeakRef advice

2011-02-14 Thread Alan Skipp
Hello everyone, I've been doing some research into weak references in ruby and from what I've read it seems that Ruby's WeakRef implementation is both inefficient and unsafe. Here is the thread discussing the matter: http://redmine.ruby-lang.org/issues/show/4168 As Macruby has a different garbag