将自动释放的对象更改为非自动释放的对象
有没有一种方法可以将自动释放的对象更改为非自动释放的对象?
NSCoder 的decodeObjectForKey 返回一个自动释放的对象,这会扰乱我应用程序中的几个内存系统。如何将其返回值更改为非自动释放的对象?
我知道我可以对其运行保留,但如果我释放它,它仍然会保持自动释放。然而,我想自己管理内存。
Is there a way to change an autoreleased object to one that is non-autoreleased?
NSCoder's decodeObjectForKey returns an autoreleased object, which messes with a couple memory systems in my app. How can I change its returned value to a non-autoreleased object?
I know I can run retain on it, but if I release it, it'll still remain autoreleased. Whereas, I want to manage the memory myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在检索自动释放对象之前设置自动释放池。它将位于那个自动释放池中。保留物体。现在释放自动释放池。您的对象不再位于自动释放池中。它已被保留,现在您有责任释放它。
Set up an autorelease pool before you retrieve the autoreleased object. It will be in that autorelease pool. Retain the object. Now release the autorelease pool. Your object is no longer in an autorelease pool. It's retained, and it's now your responsibility to release it.