In the docs for NSManagedObjectContext on the executeFetchRequest:error: method it says it returns an array, but it doesn’t mention whether the array is autoreleased or if it has a retain count = 1.
I’m assuming that it’s autoreleased, since it appears to be a convenience method, but wasn’t sure.
Edit Again
facepalm
I was checking the retain count before the autorelease pool had… released it.
Thanks for the tip on not calling retainCount – I’ll avoid it in the future. This is a good case in point where it led me astray.
According to the Object Ownership Policy, only methods prefixed with “alloc”, “new”, “copy” and “mutableCopy” return an object you own.
executeFetchRequest:error:is no exception. Therefore, you do not own the returned array and you must claim ownership of it by sending aretainmessage to it if you need to keep it around. Otherwise, it will get released (at some point in the future).The actual value of
retainCountis irrelevant.