开发者

Release of NSString Causing EXC_BAD_ACCESS

开发者 https://www.devze.com 2023-01-13 17:20 出处:网络
Thanks for your help on this one. I am pulling a NSDictionary from a plist in my main bundle and am having troubles. Here is the code:

Thanks for your help on this one.

I am pulling a NSDictionary from a plist in my main bundle and am having troubles. Here is the code:

- (void)viewDidLoad {

    // Pull in FAQ from Plist
    NSString *strFAQPlist = [[NSBundle mainBundle] pathForResource:@"FAQs" ofType:@"plist"];
    dictFAQList = [[NSDictionary alloc] initWithContentsOfFile: strFAQPlist];

    // Create indexed array to hold the keys
    arrFAQKeys = [[dictFAQList allKeys] retain];

    // Release local vars
    [strFAQPlist release];

    [super viewDidLoad];
}

I feel like I should release NSString as I have already. The problem is, when I do so, I get an EXC_BAD_ACCESS error. When I comment that release out, everything works fine. Can someone explain to 开发者_StackOverflow社区me why this is ocurring?

Thanks in advance!


pathForResource returns an autoreleased NSString.

Only call release if you've called an alloc/init method, copy method or retained it explicitly.

If you didn't create an object directly (or retained it) don't release it.

0

精彩评论

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

关注公众号