Re: Puzzling Analyzer output
Re: Puzzling Analyzer output
- Subject: Re: Puzzling Analyzer output
- From: Fritz Anderson <email@hidden>
- Date: Thu, 1 Apr 2010 08:17:50 -0500
On 1 Apr 2010, at 4:56 AM, Matt Gough wrote:
> When running the analyzer on my app, I get the following warning:
>
> warning: Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected
> return data;
> ^
>
> in the following method
>
> - (NSData*) dataNoCopyForColumnIndex:(int)columnIdx {
>
> if (sqlite3_column_type(statement.statement, columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
> return nil;
> }
>
> int dataSize = sqlite3_column_bytes(statement.statement, columnIdx);
>
> NSData *data = [NSData dataWithBytesNoCopy:(void *)sqlite3_column_blob(statement.statement, columnIdx) length:(NSUInteger)dataSize freeWhenDone:NO];
>
> return data;
> }
Your method name contains one of the Magic Words (copy) that guarantee that the returned value will be an object the caller owns and must release. Returning an object that is autoreleased would then be an error.
However, as you see, the compiler knows not to flag dataWithBytesNoCopy:length:. There are supposed to be compiler directives that control this sort of thing, but
1) I can't find documentation for a directive that would permit a "copy" method to return a nonretained object. There is an __attribute__((ns_returns_retained)), but there is no mention of an __attribute__((ns_returns_unretained)) or the like.
2) The same with a find-in-frameworks on NS_RETURNS_RETAINED (case-insensitive); that's there, but not the complement. I was stymied even in that, till I discovered it isn't used at all in the iPhone SDK.
I think the suggestion that you just not use the word "copy" unless you mean business is the best one.
— F
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden