Does NSFileHandle -readDataOfLength: return autoreleased NSData?
-
13-01-2021 - |
Question
When I call readDataOfLength:
on an NSFileHandle
instance, do I need to release the returned NSData
? Currently I'm not, but I would like to get rid of this nagging doubt.
Solution
Nope. Cocoa's memory management rules say that you only own (and thus need to release) objects returned from a method whose name contains one of "new", "alloc", "retain", or "copy" (NARC). Since that method contains none of those, you know you don't need to release it.
OTHER TIPS
The standard that is observed very consistently within Objective C libraries is that a method beginning with "alloc" or "copy" (and, I'm thinking, some other obscure verb) returns a retained object, while everything else returns an autoreleased object.
Any exceptions should be well-documented in the specs.