我有一个NSManagedobject的子类,大多数属性是动态的(由托管对象创建),但我有一些辅助属性,它们被创建为@synthesize.
释放这些物体的正确方法是什么?
- (void)didTurnIntoFault { [self.randomVar release]; [super didTurnIntoFault]; }
要么
- (void)dealloc { [self.randomVar release]; [super dealloc]; }
解决方法
覆盖didTurnIntoFault并在那里释放它们.管理对象在出现故障时不一定要解除分配.
You are discouraged from overriding
dealloc
orfinalize
becausedidTurnIntoFault
is usually a better time to clear values—a managed object may not be reclaimed for some time after it has been turned into a fault. Core Data does not guarantee that eitherdealloc
orfinalize
will be called in all scenarios (such as when the application quits); you should therefore not in these methods include required side effects (like saving or changes to the file system,user preferences,and so on).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。