开发者

XCode Product > Analyze results

I'm getting some unusual responses from the Produce > Analyze option in Xcode 4 that don't seem to make any sense to me. For example, I've always been taught to release instance variables in the dealloc method, but Analyze gives me this:

- (void)dealloc {
   [self.fileName release];
 //Incorrect decrement of the reference count of an object that is not owned at this point by the caller

Ver开发者_Go百科y confusing, can anyone shed some light on this one?

The property looks like this:

  @property (nonatomic, retain) NSString * fileName;


Confusing wording, but correct, error message.

When you do:

[self.foo release];

That can easily produce a dangling reference for the instance variable backing the foo property. I.e. as far as the compiler is concerned, there is no retain that said release is balancing.

Either do:

[fooIVar release];

(Assuming @synthesize foo = fooIVar;)

Or:

self.foo = nil;


The code should read:

[fileName release]

I get the same error if I add self.

Also do not forget to add

 [super dealloc]; 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜