[MacRuby-devel] macruby on iphone (again) - options and way forward

John Shea johnmacshea at gmail.com
Sun Oct 11 01:53:43 PDT 2009

Hello everyone.

So I think this topic is going to rear its ugly/pretty head until a  
solution becomes available, and I myself would really like to be able  
to use macruby code on the iphone.

So I have put down my naive thoughts as to what are the issues.

I am a complete novice when it comes to GC, so I am sorry if this is  
all obvious or erroneous - but the important part is the discussion -  
which i hope many of you will add to.

Anyway it could be that I don't know enough about the subject to make  
sense of it. But a way to perhaps getting more people to work on  
getting macruby on the phone could be:

1. Describe the current GC situation on the mac & macruby in terms of  
2. Describe an appropriate architecture for how GC would work on the  
iphone, how the programmer interacts with it in coding or compiling.
3. Describe the various parts of work that have to be done to to  
implement 2.
4. Make some suggestions of similar coding efforts or current code  
files or other references that people can use/copy to build a proof of  

The following are my versions of 1 and 2:

Point 1:
My assumption is that currently macruby hooks into objective c's GC -  
autozone (this one ? http://www.opensource.apple.com/source/autozone/autozone-77.1/) 
  via ruby's ObjectSpace.

Point 2:
The iphone does not have GC so therefore in order to run macruby  
something needs to collect the garbage.

My other assumption is that you cannot run interpreted code on the  
iphone (or iphone simulator) so when developing for iphone the ruby  
code would need to be compiled during the build phase.

So I can think of two ways to do collect the garbage.

Firstly port autozone to the iphone - integrate macruby more or less  
as now - include it as a framework or something.
   - i am concerned that the separate autozone thread(s) may not play  
well with the iphone processor
   - in addition the threads need to be interruptible, when phone  
calls come in or the home button is pressed - i can imagine including  
the autozone controller in the responder chain (in order to receive  
the shutdown command) would not be trivial.

I am wondering if the above complexity is why Laurent always refers to  
"emulating" autozone rather than including it or porting it.

The other option i can think of is in the build phase insert the  
necessary retains, releases and autoreleases into the code. By either:

	i) the developer including the calls manually, which are then  
compiled/translated to the appropriate C/ObjC commands. (I have gone  
off this idea a bit because the code would be hard to test in  
isolation (unless there were special compiler codes normally ignored  
by the ruby interpreter), and would make it hard to drop in any nice  
ruby code/libraries, and later on hard to fix code if an official GC  
ever arrives).

	ii) have a script which traverses the ruby code - and adds dealloc  
methods for instance methods, adds releases to scope bound variables  
etc, etc.
(I like this option the best, though i have little idea how to  

So do you all think i have described the situation properly?

If so perhaps someone (more knowledgeable) could provide some hints to  
points 3 and 4 above?

Or if i haven't described the situation properly then the whole stack  
of points 1-4 would (I think) help us move forward - and help people  
contribute to a solution.


More information about the MacRuby-devel mailing list