1

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.

Parag Bafna
  • 22,143
  • 7
  • 65
  • 138
jinglesthula
  • 4,162
  • 4
  • 43
  • 72

2 Answers2

3

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 a retain message to it if you need to keep it around. Otherwise, it will get released (at some point in the future).

The actual value of retainCount is irrelevant.

Community
  • 1
  • 1
albertamg
  • 28,172
  • 6
  • 61
  • 70
2

It returns an object that will go away sometime in the future unless you retain it. Whether it is autoreleased or not is an implementation detail. Beyond that, there is no way for you to tell whether or not something is autoreleased.

Also:

Do not call retainCount

It is useless; the absolute retain count of an object is an implementation detail and may be any number of values for no apparent reason

bbum
  • 160,467
  • 23
  • 266
  • 355