views:

63

answers:

1

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 me why this is ocurring?

Thanks in advance!

+3  A: 

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.

MarkPowell
Thanks for your help. In the documentation, is there a way to know if what's being returned is autoreleased to avoid this type of issue again? Or, is it a hard fast rule that anything that I didn't directly create is autoreleased?
Jesse Bunch
It's convention (and you can count on it being followed by the Cocoa API). Anything that you are responsible for releasing will have "init" or "copy" in the front of the name. For instance, NSArray arrayWithArray: will be autoreleased, initWithArray: will not be.
MarkPowell