• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why does releasing this array cause a crash?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does releasing this array cause a crash?


  • Subject: Re: Why does releasing this array cause a crash?
  • From: James Cicenia <email@hidden>
  • Date: Tue, 10 Mar 2009 17:50:49 -0500

Ah...

Thank you. I understand now.

James

On Mar 10, 2009, at 5:41 PM, Randall Meadows wrote:

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


References: 
 >Why does releasing this array cause a crash? (From: James Cicenia <email@hidden>)
 >Re: Why does releasing this array cause a crash? (From: Randall Meadows <email@hidden>)

  • Prev by Date: Re: Garbage collected and non-garbage collected
  • Next by Date: Re: Garbage collected and non-garbage collected
  • Previous by thread: Re: Why does releasing this array cause a crash?
  • Next by thread: What is using up so much memory here?
  • Index(es):
    • Date
    • Thread