I have a quick memory management question. Here is the code:
When I release the temp object, the app crashes. If I remove that line, it runs, but of course it will leak memory.
I've been looking through the documentation for hours and I've looked at countless examples and I can't figure out why this crashes. I alloc an object, do something with it, then release it. Everything I've written conforms to the documentation, as far as I understand it. What am I missing here?
Code:
NSArray *keys = [[[NSArray alloc] initWithObjects: @"1", @"2",nil] autorelease];
NSMutableArray * temp = [[NSMutableArray alloc] init];
temp = [NSMutableArray arrayWithArray:keys];
[temp release];
When I release the temp object, the app crashes. If I remove that line, it runs, but of course it will leak memory.
I've been looking through the documentation for hours and I've looked at countless examples and I can't figure out why this crashes. I alloc an object, do something with it, then release it. Everything I've written conforms to the documentation, as far as I understand it. What am I missing here?