detecting double free object, release or not release ...
Posted
by mongeta
on Stack Overflow
See other posts from Stack Overflow
or by mongeta
Published on 2010-06-02T15:01:47Z
Indexed on
2010/06/02
15:03 UTC
Read the original article
Hit count: 425
Hello,
If we have this code in our interface .h file:
NSString *fieldNameToStoreModel;
NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
DataEntered *dataEntered;
In our implementation file .m we must have:
- (void)dealloc {
[fieldNameToStoreModel release];
[fetchedResultsController release];
[managedObjectContext release];
[dataEntered release];
[super dealloc];
}
The 4 objects are assigned from a previous UIViewController, like this:
UIViewController *detailViewController;
detailViewController = [[CarModelSelectViewController alloc] initWithStyle:UITableViewStylePlain];
((CarModelSelectViewController *)detailViewController).dataEntered = self.dataEntered;
((CarModelSelectViewController *)detailViewController).managedObjectContext = self.managedObjectContext;
((CarModelSelectViewController *)detailViewController).fieldNameToStoreModel = self.fieldNameToStoreModel;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
The objects that now live in the new UIViewController, are the same as the previous UIViewController, and I can't release them in the new UIViewController ?
The problems is that sometimes, my app crashes when I leave the new UIViewController and go to the previous one, not always. Normally the error that I'm getting is a double free object.
I've used the malloc_error_break but I'm still not sure wich object is.
Sometimes I can go from the previous UIViewController to the next one and come back 4 or 5 times, and the double free object appears.
If I don't release any object, all is working and Instruments says that there are no memory leaks ...
So, the final question, should I release those objects here or not ?
Thanks,
m.
© Stack Overflow or respective owner