开发者

Using self on iVars in dealloc?

开发者 https://www.devze.com 2023-01-22 15:36 出处:网络
Usually I write my dealloc to look like this: - (void)dealloc { [coffeeList release]; [super dealloc]; } But today I typed (see below) and was a little puzzled why I got an error running the code t

Usually I write my dealloc to look like this:

- (void)dealloc {
    [coffeeList release];
    [super dealloc];
}

But today I typed (see below) and was a little puzzled why I got an error running the code through the CLANG static analyser. As I say I don't usually add self to iVars in dealloc, but was just a little curious when I spotted this as to what was going on.

- (void)dealloc {
    [[self coffeeList] release];
    [su开发者_运维技巧per dealloc];
}

gary.


I'm just guessing that clang notices [self something] release (or [self.something release]) goes against the memory management conventions. An object returned from a method not having "new", "init", or "copy" in its name should be autoreleased, so releasing it again would appear to be an over-release error.


Because that's really bad form, and goes against how you should be doing things. CSA doesn't just check for semantic errors, it also checks that you're doing things the way you should be. Where the way you should be, is the way things are done in the documentation.


Is coffeeList declared as a property (and set to retain)? Then you should probably do:

[self.coffeeList release];
0

精彩评论

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