开发者

XCode Product > Analyze results

开发者 https://www.devze.com 2023-04-06 16:12 出处:网络
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 de

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

精彩评论

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

关注公众号