Should I release a pointer that's pointing to an item in an array?
Not quite sure how to phrase this, but should I release a variable in this situtation:
NSString *string = @"HELLO WORLD";
NSArray *array = [NSArray arrayWithObject:string];
NSString *shouldIReleaseThis = [array objectAtIndex:0];
NSLog(@"%@", shouldIR开发者_如何学JAVAeleaseThis);
//???? [shouldIReleaseThis release] ??????
//Do stuff with array
Should I release it? Why or why not?
You don't own it (you didn't get that reference from new
, alloc
, retain
or copy
), so you shouldn't release it. See Apple's memory management programming guide for a brief but complete overview of the memory management rules in Cocoa.
精彩评论