Re: Why does releasing this array cause a crash?
Re: Why does releasing this array cause a crash?
- Subject: Re: Why does releasing this array cause a crash?
- From: Randall Meadows <email@hidden>
- Date: Tue, 10 Mar 2009 16:41:35 -0600
On Mar 10, 2009, at 4:35 PM, James Cicenia wrote:
NSMutableArray *arraySubType = [[NSMutableArray alloc]init];
OK, this array, you *should* release, yes.
Then in a loop from the database I have:
while (sqlite3_step(statement) == SQLITE_ROW) {
if(![aDict objectForKey: [NSString stringWithUTF8String:(char
*)sqlite3_column_text(statement, 1)]]){
NSMutableArray *tmpArray = [[NSMutableArray alloc]init];
[aDict setValue:tmpArray forKey: [NSString stringWithUTF8String:
(char *)sqlite3_column_text(statement, 1)]];
[tmpArray release];
}
arraySubType = [aDict objectForKey: [NSString stringWithUTF8String:
(char *)sqlite3_column_text(statement, 1)]];
You have now just overwritten the previous value of arraySubType, thus
leaking it. You now have a handle to a completely different object,
which is autoreleased. This is why when you do release it, you crash
later.
If you do not use arraySubType between the alloc/init above and this
line, then you do not need to alloc/init it, just declare it only.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden