Here’s a code example to show what I mean:
- (void) setup {
[self setupObjectModel];
[self setupStoreCoordinator];
}
- (void) setupObjectModel {
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"];
self.managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] autorelease];
}
In case
managedObjectModelis astrongproperty or defined with attributeretain, the setter will automatically retain the passed argument, thusautoreleaseing it will prevent a memory leak (if you don’t do it, the retain count of theNSManagedObjectModelwill be 2 although onlymanagedObjectModelpoints to it.)This is equivalent to
assuming the setter has the default behaviour