Cocoa“内存管理编程指南”文档说:
You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message. You are responsible for relinquishing ownership of objects you own using release or autorelease. Any other time you receive an object, you must not release it.
这是否也适用于 [NSNumber numberWithFloat:] 或 [CAAnimation 动画] 等便捷方法?我是否应该释放这些?
谢谢!
最佳答案
对于便捷方法来说,该陈述仍然正确,特别是最后一句
Any other time you receive an object, you must not release it.
这意味着您必须不释放这些对象,除非您事先明确向它们发送保留消息。
关于Cocoa内存管理规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3186259/