views:

253

answers:

1

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?

+3  A: 

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.

Ivan
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 :)
Yar
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
Yar
Just for the record, Apple already has garbage collector implemented in their javascript engine.
Ivan
@Ivan I've often wondered why one couldn't just use the GC you mentioned in Objective-C anyway...
Yar