[MacRuby-devel] WeakRef advice

Alan Skipp al_skipp at fastmail.fm
Mon Feb 14 05:48:58 PST 2011


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 garbage collector I don't know if these problems are also present?

I am working on a blocks based API for Key Value Coding and need to keep a weak reference to objects. 
Here is a very basic example of how this would look in garbage collected Objective-C:

@interface Observer : NSObject
{
	 __weak id obj;
}

@implementation
- (Observer *)initObservedObject:(id)object
{
	obj = object;
}


Essentially I just need a Macruby equivalent of the above. Is there a simple way to have a weak referenced instance variable in Macruby?

al


More information about the MacRuby-devel mailing list