开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜