"Homepwner" analyze error


Analyze warned about following method in PossessionStore.m of “Homepwner”:
“Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected”.

+ (id)allocWithZone:(NSZone *)zone { return [self defaultStore]; }
Compiler warned about following method in PossessionStore.m of “Homepwner”:
“Conflicting distributed object modifiers on return type in implementation of ‘release’”.

- (void)release { // Do nothing }


What chapter is this from? This section is for chapter 3.


It is chapter 18.


I’m not nearly that far, and again this section of the board is for chapter 3, but let’s take a peek.

In scanning the ~9 pages of chapter 18 (on localization), I don’t see either of the routines mentioned, but let’s push on.

I’ve only ever seen -release overridden in a singleton pattern. Checking the index for singleton sends me to pages 177-180…and sure enough, that’s where the code is. Assuming you’ve implemented all the other methods as well, you should be fine.

If you like, you can compare the book’s implementation with Apple’s (in the very last section of the Cocoa Objects chapter). They’re not an exact match, but they’re pretty darned close.


Yeah, the analyzer result is a false positive. Happens because of the name of the method doesn’t begin with alloc/new/copy, you can safely ignore it.

The release method should actually be declared as - (oneway void), instead of just - (void). This was an error on my part; the oneway keyword is a holdover from something called Distributed Objects, which are to my knowledge, deprecated on Mac OS X and never available on iOS. For backwards compatibility, I imagine NSObject had to keep this qualifier.