[MacRuby-devel] Garbage Collector in MacRuby

Laurent Sansonetti lsansonetti at apple.com
Sat Apr 10 17:47:39 PDT 2010


Hi Daniel,

MacRuby uses the Objective-C garbage collector, and also runs the Objective-C runtime in GC mode. It basically means that you can use Cocoa objects without the need to retain/release them, and they will be automatically collected at runtime once there is no reference to them anymore. This is also true for pure Ruby code.

Please note that the collector is not deterministic and runs on its own thread(s) (and also collects memory from there). So, setting variables to nil or calling GC.start can help but there is no guarantee that the objects will be immediately freed. 

In general you should not care about these issues. Just don't think about managing memory and it should work fine. If you find a problematic case, let us know :-)

Laurent

On Apr 10, 2010, at 8:44 AM, Daniel Lopes wrote:

> Hello, I would like to know more about the garbage collector. In Obj-c even when we have GC enabled we should set nil to the vars (which sometimes is also useful in pure ruby). Correct me if I'm wrong but in MacRuby we can't use GDB, right? We still able to use profile tools? I should set all vars to nil or it will be treated like normal ruby code and I need set to nil only the objects that I want to be released now?
> 
> Thanks.
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list