Question #1 : As a rule, I never release an object if I don't have to. Assuming that stringWithUTF8String has an autorelease inside itself, I don't have to do "return [... autorelease]", right?
-(NSString*)nonNullDBString:(const unsigned char*)value {
if(value == nil) {
return @"";
} else {
return [NSString stringWithUTF8String:(char *)value];
}
}
Question #2 : In my class I have the attribute: "const uint8_t *bytes;". In the dealloc method must I call "bytes = nil;" or "free(bytes);", or nothing at all?
Question #3 : For @property(nonatomic, retain) variables in my classes, what is the best practice of dealloc'ing, is it "self.foo = nil;" or " [foo releease] (what I am doing now) ". Additionally, I do not want to mess with KVO issues, whatever they are...
A1) Right. Your snippet is correct.
A2) If you malloc
'ed it then call free
(it's a C after all). No need to do foo = nil
- your object will be dead upon return from dealloc
, nobody cares what this pointer value is anymore.
A3) [foo 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.