[MacRuby-devel] WeakRef advice

Laurent Sansonetti lsansonetti at apple.com
Mon Feb 14 14:09:00 PST 2011


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 at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110214/18a75ec3/attachment.html>


More information about the MacRuby-devel mailing list