Why cannot XCode static analyzer detect un-released retained properties?

风流意气都作罢 提交于 2019-12-11 07:26:01

问题


I have this retained property declared like this:

@property (nonatomic, retain) NSMutableDictionary *codes;

then I synthesize this:

@synthesize codes;

I use the property like this:

self.codes = [NSMutableDictionary dictionary];

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

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?


回答1:


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

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.

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.




回答2:


If you havent change anything from the configuration, whenver you target ios5+ you will automatically be using ARC (Automatic Reference Counting) which doesnt require you to release or retain.

The most disruptive change in iOS 5 is the addition of Automatic Reference Counting, or ARC for short. ARC is a feature of the new LLVM 3.0 compiler and it completely does away with the manual memory management that all iOS developers love to hate.

This is a post by iOS Tutorial Team member Matthijs Hollemans, an experienced iOS developer and designer.



来源:https://stackoverflow.com/questions/10944736/why-cannot-xcode-static-analyzer-detect-un-released-retained-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!