[MacRuby-devel] MacRuby and ARC was: Advice for Total Tyro

Igor Evsukov igor.evsukov at gmail.com
Sun Oct 16 23:11:35 PDT 2011


Hi Henry,

>> And it's impossible to make Ruby to use ARC.
> 
> Why?
For memory management Objective-C uses a paradigm called "reference counting". The idea is very simple – when You need an object – You increase it reference count, when You no longer need it – You should decrease it. For example

NSString *name = @"Henry";

//when [[... alloc] init...] called (new object get created) – reference count of object is set to 1.
//who create's object is responsible to delete it
NSString *greeting = [[NSString alloc] initWithFormat:@"Hello %@",name];

//assume that greetings in an instance of NSMutableArray
[greetings addObject:greeting];

//we no longer need a greeting variable
[greeting release];

Everything is ok with this model, but You should manually track circular references.

ARC is just a smart preprocessor that knows Cocoa memory conventions and add's retain/release/autorelease calls to Your source code. And it can't figure out what to with circular references.

In Ruby we have garbage collector which is acts in whole different way – instead of modifying source code it track all created objects and delete one's that are no longer accessible from Your program. 

So, basically, ARC and GC are two conceptually different things which are even not replaceable by each other(circular references).

I encourage You to watch a BostonRB talk ( http://bostonrb.org/presentations/macruby-what-is-it-and-why-should-i-care-part-1 ) by Joshua Ballanco (one of the MacRuby developers). In his talk he sad that GC isn't a major issue with bringing MacRuby to iOS. 

On 17 окт. 2011, at 08:43, Henry Maddocks wrote:

> 
> On 16/10/2011, at 9:07 PM, Igor Evsukov wrote:
> 
>> And it's impossible to make Ruby to use ARC.
> 
> Why?
> 
> Henry
> 
> _______________________________________________
> 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/20111017/6db9c132/attachment-0001.html>


More information about the MacRuby-devel mailing list