开发者

Does NSFileHandle -readDataOfLength: return autoreleased NSData?

开发者 https://www.devze.com 2023-03-31 06:54 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消