为什么 XCode 静态分析器无法检测未发布的保留属性? [英] Why cannot XCode static analyzer detect un-released retained properties?

查看:36
本文介绍了为什么 XCode 静态分析器无法检测未发布的保留属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样声明的保留属性:

I have this retained property declared like this:

@property (nonatomic, retain) NSMutableDictionary *codes;

然后我合成这个:

@synthesize codes;

我使用这样的属性:

self.codes = [NSMutableDictionary dictionary];

然后,我忘记在我的dealloc 中说[codes release];.

Then, I forget to say [codes release]; in my dealloc.

当我在 XCode 4.3.2 中运行 Analyzer 时,这不会显示为问题.我的基础 SDK 是 iOS 5.1,我的编译器是 Apple LLVM 编译器 3.1

When I run Analyzer in XCode 4.3.2, this is not shown as an issue. My base SDK is iOS 5.1 and my compiler is Apple LLVM compiler 3.1

为什么分析器没有发现这个?

Why doesn't analyzer pick this up?

推荐答案

我想这是因为分析器无法可靠地检测跨方法/库边界的保留/释放问题.

I imagine it's because the analyzer can't reliably detect retain/release issues across method/library boundaries.

可以想象,您可以将 codes 数组的所有权传递给某个外部方法或库,这些方法或库稍后会为您释放它.这将是不好的做法,因为接收方法应该在需要时保留它,但我见过没有经验的开发人员做过这种事情.

You could conceivably pass ownership of your codes array to some external method or library which will release it later on for you. This would be bad practice because the receiving method should just retain it if it needs it, but I've seen this kind of thing done by inexperienced developers.

所以你可能会在课堂上的某个地方看到这个:

So you might see this in your class somewhere:

[SomeAPI takeThisArrayAndReleaseItLater:codes];

分析器无法知道您的类不再负责释放数组.尽管您没有遵循良好的内存管理实践,但向您发出警告是不正确的.

The analyzer has no way to know that your class is no longer responsible for releasing the array. To give you a warning would be incorrect, despite the fact that you are not following good memory management practices.

分析器非常擅长只对实际问题发出警告.我认为我从未见过 Beta 版本之外的误报,这是一件好事.

The analyzer is very good at only warning on real issues. I don't think I've ever seen a false-positive outside of betas builds, which is a good thing.

这篇关于为什么 XCode 静态分析器无法检测未发布的保留属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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