8

It's well known that Apple does not provide automatic garbage collection on the iPhone to prolong battery life. Yet MonoTouch apps, which reportedly run perfectly on the iPhone (and many are sold through the AppStore, therefore are approved by Apple), do have automatic garbage collection.

  1. Is this automatic garbage collection, or does MonoTouch just manage all the retain/release stuff for you?
  2. If it is automatic garbage collection, wouldn't that be a drain on battery?

Edit: If your answer to #1 is "yes" and your answer to #2 is "no," why?

Historical Edit: It should be noted that Apple has decided to go a different route for iOS 5.0 and implement ARC (also allowing code compiled against the same SDK to work on iOS 4.x as well).

Community
  • 1
  • 1
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421

1 Answers1

6

Yes it has real garbage collection. MonoTouch is based on Mono. Which uses Boehm-Demers-Wiser Conservative Garbage Collector (compacting garbage collector is in development). It is capable of automatically collecting unreferenced objects. Using C# and .NET will be less optimal then using Objective-C/C++/C when it comes to battery life, as more CPU clocks will be needed to accomplish the same job, but if your app is not CPU intensive this would probably be negligible. I don't think you will have noticable impact on battery life.

Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317
Ivan
  • 1,735
  • 1
  • 17
  • 26
  • Great answer: in fact I was thinking about implications of GC for the iPhone 4.0 agreement. Using a GC could be seen as "cheating," in some sense, which would cause problems like lower battery life. But I was also thinking about MonoTouch while looking at a ton of `[thing release]` statements and getting distracted :) – Dan Rosenstark May 12 '10 at 13:42
  • 1
    While we're here, though, check out MonoTouch's speculation on whether they'll be booted by the new agreement: http://www.mono-project.com/newstouch/archive/2010/Apr-19.html – Dan Rosenstark May 12 '10 at 13:44
  • Just for the record, Apple already has garbage collector implemented in their javascript engine. – Ivan May 12 '10 at 14:52
  • 1
    I've often wondered why one couldn't just use the GC you mentioned in Objective-C anyway... – Dan Rosenstark May 12 '10 at 14:53