I'm wondering if someone could explain why the retain count of a newly created managed object is 2. Here is the code I'm working with:
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
Album *newAlbum = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
NSLog(@"Album retain count: %d", [newAlbum retainCount]);
According to the documentation for the insertNewObjectForEntity
method, it returns a newly created autoreleased object. So I would expect the retain count to be 1 instead of 2. Can someone explain?
Retain count is not guaranteed to be accurate, you may have encountered such a case.
I've made a sample project in which an object alloc/init was having a retain count of two, then 0 when released, etc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With