ios – iphone NSManagedObject – 解除分配的正确方法?

前端之家收集整理的这篇文章主要介绍了ios – iphone NSManagedObject – 解除分配的正确方法?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个NSManagedObject的子类,大多数属性是动态的(由托管对象创建),但我有一些辅助属性,它们被创建为@synthesize.

释放这些物体的正确方法是什么?

- (void)didTurnIntoFault
{
     [self.randomVar release];
     [super didTurnIntoFault];
}

要么

- (void)dealloc
{
     [self.randomVar release];
     [super dealloc];
}

解决方法

覆盖didTurnIntoFault并在那里释放它们.管理对象在出现故障时不一定要解除分配.

documentation

You are discouraged from overriding dealloc or finalize because didTurnIntoFault 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 either dealloc or finalize 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).

猜你在找的iOS相关文章