开发者

allocWithZone object need to be release

Does the object returned by allocWithZone need to be released? i.e. is it the same as alloc and new?

- (id) copyWithZone: (NSZone *) z开发者_JS百科one
{
Engine *engineCopy;
engineCopy = [[[self class] allocWithZone:zone]init];

return (engineCopy);
}


Yes you still need to release it. See the documentation for NSObject: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html

If you are using managed memory (not garbage collection), this method retains the object before returning it. The returned object has a retain count of 1 and is not autoreleased. The invoker of this method is responsible for releasing the returned object, using either release or autorelease.


new combines alloc and init. It's the alloc that requires releasing; allocWithZone: should almost never be called directly (alloc calls it internally), and is mostly around for legacy reasons. Update similarly, copyWithZone: should (almost) never be called directly; however, copy will call it implicitly. Inside copyWithZone: is probably the only place where I have ever called allocWithZone:.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜