質問

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.

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top