Code Sample:
NSString *str= [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectS开发者_开发百科tatement, 1)];
Test *t=[[Test alloc] init];
t.str=[str copy]; // why use "copy" here?
[str release];
It looks to be bad coding, for two reasons. Since str
is being discarded, you might as well assign it, rather than a copy, to t.str
. Second, and more importantly, setters should take care of retaining or copying data.
Should be:
NSString *str= [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 1)];
Test *t=[[Test alloc] init];
t.str=str; // No point copying to release original.
精彩评论