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(@"%@", shouldIReleaseThis);
//???? [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,retainorcopy), 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.