开发者

Adding Garbage Collection to iPhone?

开发者 https://www.devze.com 2023-01-16 16:18 出处:网络
MonoTouch has automatic garbage collection on the iPhone. Couldn\'t someone prematurely impl开发者_JAVA技巧ement garbage collection for Objective-C on iOS? I\'m not the guy to do it, but I\'m curious

MonoTouch has automatic garbage collection on the iPhone. Couldn't someone prematurely impl开发者_JAVA技巧ement garbage collection for Objective-C on iOS? I'm not the guy to do it, but I'm curious as to why or whether this is impossible.

I know that projects like this exist: what does it take to use them on iOS? Since they are in C/C++ anyway, and Objective-C contains those languages as subsets, but yet, those languages are actually aware of the system architecture... I'm out of my depths here...

While we're here, if anyone knows of any attempts to implement a GC on iOS, links would be helpful...


I don't think it's possible. The problem is that Objective-C is used inside the system library too. In OS X where garbage-collected Objective-C is supported, there are in fact three modes when you compile a code:

  1. the function compiled can be only called from non-GC environment.
  2. the function compiled can be only called from GC environment.
  3. the function compiled can be called both from GC and non-GC environment.

See the discussion here, for example. The point is that the system library needs to be in the third mode in order for the OS to support both non-GC and GC apps. And in OS X, the libraries come in this hybrid mode. In iOS, I guess it comes in the mode 1. (I don't know for sure because I haven't jailbroken my phone, though.)

If you have complete control over both the system library and your app, it's possible to make them all garbage collected, but unfortunately we're not in that stage yet.

I'm sure we'll have GC in iOS in two years.


Nothing stops you from building your own garbage collector for your app. Or importing another project that will handle it. Again, for your app.

more discussion:

Is garbage collection supported for iPhone applications?

0

精彩评论

暂无评论...
验证码 换一张
取 消