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 shouldn't need to worry about leaks. Is 
there another use case that I'm forgetting? 

Laurent

On Feb 14, 2011, at 5:48 AM, Alan Skipp wrote:

> 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
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel@lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to