简体   繁体   中英

Using self on iVars in dealloc?

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];
    [super 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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM