Reputation: 5435
When developing with Objective-C on iOS, memory management currently must be performed by the developer. Some of the other mobile platforms use automatic garbage collection to remove the need for managing memory.
What could be the reasons why garbage collection is not used on the iOS devices?
Upvotes: 14
Views: 4173
Reputation: 12979
At WWDC 2011, Apple explained that they didn't want garbage collection on their mobile devices because they want apps to be able to run with the best use of the provided resources, and with great determinism. The problem with garbage collection is not only that objects build up over time until the garbage collector kicks in, but that you don't have any control over when the garbage collector will kick in. This causes non-deterministic behavior that could lead to slowdowns that could occur when you don't want them.
Bottom Line: You can't say, "OK. I know that these objects will be freed at X point in time, and it won't collide with other events that are occurring."
Upvotes: 10
Reputation: 86651
The main reason is probably memory load and performance. Reference counting has a smaller memory profile in that it allows the amount used by the application grow much more than reference counting. Also, there is a performance issue in that when the garbage collector runs, other threads have to be stopped. This is not really a huge issue on Macintoshes with fast multicore processors but could cause the UI to stutter on mobile devices.
The debate may be moot soon anyway. Clang / LLVM has just had a new feature added called automatic reference counting. This leverages the analysing capability to automatically put in the retains, releases and autoreleases so that the programmer doesn't have too.
Upvotes: 3
Reputation: 6320
The problem with garbage collection is that memory usage grows until it's collected, so there might be more memory allocated than necessary. That's bad for devices with restricted memory and no option to swap.
When the garbage collector runs, it scans the heap to find memory that's no longer being used, and that's an expensive process, that will slow down your device until is has completed.
Upvotes: 20