I have a NSMutableArray of QuoteMap objects. When I add one using the below code and navigate to another view that uses the same data, it bombs out with an EXC_BAD_ACCESS when trying to access that array.
You can see below that the last object in the array is “NSObject” instead of “QuoteMap”.

Here is where I add the quoteMap:
- (void)insertQuoteMap:(QuoteMap*)qm {
// THEN TAKE THE QUOTE_MAP_ID, SUBJECT_ID AND QUOTE_ID AND INSERT INTO QUOTE_MAP TABLE
NSInteger quoteMapId = [qm.quote_map_id intValue];
NSInteger subIdInt = [qm.subject_id intValue];
NSInteger quoteIdInt = [qm.quote_id intValue];
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
FMDatabase *database = [FMDatabase databaseWithPath:appDelegate.getDBPath];
if ([database open]) {
[database executeUpdate:@"insert into QUOTE_MAP(quote_map_id, quote_id, subject_id) values(?, ?, ?)",
[NSNumber numberWithInt:quoteMapId], [NSNumber numberWithInt:quoteIdInt], [NSNumber numberWithInt:subIdInt]];
[database close];
}
NSLog(@"QuoteMap inserted the quote_map_id of: %@", qm.quote_map_id);
//Add the object
[appDelegate addQuoteMap:qm];
[qm autorelease];
};
This is what calls the above method:
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
QuoteMap *qm = [[QuoteMap alloc] init];
NSInteger newQuoteMapId = [appDelegate getNextQuoteMapId];
NSLog(@"quote_map_id= %d subId = %@ quoteId = %@", newQuoteMapId, stringOfSubjectId, selectedQuote.quote_id);
// INSERT INTO QUOTE_MAP TABLE
NSString *stringOfId = [NSString stringWithFormat:@"%d", newQuoteMapId];
qm.quote_map_id = stringOfId;
qm.subject_id = stringOfSubjectId;
qm.quote_id = selectedQuote.quote_id;
//qm.isDirty = YES;
[qm insertQuoteMap:qm];
//Add it to the array.
[qmv.quoteMaps addObject:qm];
[qmv.tableView reloadData];
if (tableAlert.type == SBTableAlertTypeMultipleSelct) {
UITableViewCell *cell = [tableAlert.tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone)
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
else
[cell setAccessoryType:UITableViewCellAccessoryNone];
[tableAlert.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
//release
[qm autorelease];
Your
- (void)insertQuoteMap:(QuoteMap*)qmdoesn’t own the QuoteMap that’s passed to it, so it shouldn’t autorelease it at the end.When classes change at runtime like that, it’s frequently a result of an overrelease, where the original object no longer exists and the area it used to occupy in memory has since been filled with a another object.