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, Alan Skipp wrote:

> 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 while 'A', is in use, when 
> this is no longer the case I want 'B' to self destruct. However, 'B' is held 
> in a hash and holds a reference to 'A', so neither object goes out of scope 
> and neither can be garbage collected.
> 
> If I changed the implementation perhaps I could avoid this problem, though 
> I'm not sure what the solution would be as yet.
> 
> al
> 
> On 14 Feb 2011, at 22:09, Laurent Sansonetti wrote:
> 
>> 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
> 
> _______________________________________________
> 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