我如何确定一个编译的Objective-C应用程序是否使用垃圾收集? [英] How can I determine if a compiled Objective-C app is using garbage collection?

查看:149
本文介绍了我如何确定一个编译的Objective-C应用程序是否使用垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我在Mac上的任何应用程序,有没有办法告诉它是否已经启用GC编译,或者是否正在进行手动内存管理?

For any application that I have on my Mac, is there a way to tell if it was compiled with GC enabled, or if it's doing manual memory management?

推荐答案

我发现了答案这里。请注意,原始讯息是错误,但包含 Mark Rowe 发表评论,这是一位苹果工程师,指明了方向。

I found the answer here. Mind you that the original post is wrong, but contains a comment by Mark Rowe, an Apple engineer, that points the way.

我已经重新运行它在当前操作系统(10.6.4)的机器上提到的 otool 命令。以下是输出:

I have re-run the otool commands he mentions on my machine with the current OS (10.6.4). Here's the output:


$ uname -a
Darwin meaningless.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386

### Mail doesn't use GC
$ otool -oV /Applications/Mail.app/Contents/MacOS/Mail | tail -3
Contents of (__DATA,__objc_imageinfo) section
  version 0
    flags 0x0

### Xcode supports GC and retain/release
$ otool -oV /Developer/Applications/Xcode.app/Contents/MacOS/Xcode | tail -3
Contents of (__DATA,__objc_imageinfo) section
  version 0
    flags 0x2 OBJC_IMAGE_SUPPORTS_GC

Mark Rowe的说明


此处感兴趣的字段是 __ image_info 段的 __ OBJC 段。
如果支持垃圾收集,它将具有值 0×2 ,并将显示为GC RR到
表示无论是垃圾收集和保留/释放。如果需要垃圾收集
,则该字段将具有值 0×4 ,并且将被示为仅GC
只支持垃圾回收,保留/释放不可用。字段
也可以包含其他值,但这两个值是与垃圾回收相关的唯一值。

The field of interest here is the "flags" field of the __image_info section of the __OBJC segment. If garbage collection is supported it will have the value 0×2 and will be shown as "GC RR" to represent that both garbage collection and retain/release are supported. If garbage collection is required then the field will have the value 0×4 and will be shown as "GC-only" indicating that only garbage collection is supported and that retain/release is not available. The field can also contain other values, but those two are the only values that are relevant to garbage collection.

这篇关于我如何确定一个编译的Objective-C应用程序是否使用垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆