objective c - EXC_BAD_ACCESS error when removing object from NSMutableDictionary -
i have nsmutabledictionary datasource uitableview. trying implement delete mode , having issue.
i logging key trying remove object corresponds issue seems might related trying access unallocated memory or something. here implementation of tableview:commiteditionstyle:forrowatindexpath:
- (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath { if (editingstyle == uitableviewcelleditingstyledelete) { // delete row data source. nsarray * keys = [userlist allkeys]; nsnumber *keytoremove = [keys objectatindex:indexpath.row]; nslog(@"key remove: %@",keytoremove); nslog(@"object @ key: %@",[userlist objectforkey:keytoremove]); [userlist removeobjectforkey:keytoremove]; [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade]; [keys release]; [keytoremove release]; } else if (editingstyle == uitableviewcelleditingstyleinsert) { // create new instance of appropriate class, insert array, , add new row table view. } }
this method runs , error. 2 nslog statements output correct key , it's corresponding value.
can tell me i'm doing wrong?
thanks
you don't own keys
or keystoremove
, should not releasing them. suggest reading on cocoa memory management rules.
Comments
Post a Comment