开发者

Releasing a property with self.property - Errors in the Analyzer

开发者 https://www.devze.com 2023-04-01 23:52 出处:网络
I\'ve an UIViewController with a property @property (nonatomic, retain) NSMutableArray *speakerFetchResults;

I've an UIViewController with a property

@property (nonatomic, retain) NSMutableArray *speakerFetchResults;

Then I set the property in viewWillAppear with

 self.speakerFetchResults = [[[self.speakerViewContext executeFetchRequest:request error:&error] mutableCopy] autorelease];

and want to release it again in the UIViewController's dealloc method with

[self.speakerFetchResults release];

But, if I analyze 开发者_StackOverflow社区my file I get on the [self.speakerFetchResults release]; the following warning:

Incorrect decrement of the reference count of an object that is not owned at this point by the caller.

Furthermore (I've testet it out) I get this message on all

[self.anything release]

issues.

So I'm a little bit confused and removing all "self." in this releases or in general cause a lot of errors in the programm. So I think the analyzer is wrong, but I just want to ask you for some help.

What do you think?

Thanks for all your help.


You shouldn't call release on the object returned by the getter (the getter may have side effects, custom logic, return autoreleased objects, etc. so you can not assume that [self.speakerFetchResults release] and [speakerFetchResults release] have the same results).

You can simply do:

self.speakerFetchResults = nil; // this releases the old value

Or, in dealloc, where the use of accessors is discouraged:

[speakerFetchResults release];
0

精彩评论

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