开发者

Core Data entity lifecycle? When are they released?

开发者 https://www.devze.com 2023-01-11 12:21 出处:网络
I am importing a bunch of data from a web service on 开发者_运维技巧a background thread and I randomly run into bad access problems, I believe mostly from assigning relationships.

I am importing a bunch of data from a web service on 开发者_运维技巧a background thread and I randomly run into bad access problems, I believe mostly from assigning relationships.

I am wondering how long the new entities I create and save hang around?


Core Data follows the same rules as any other object in Objective-C except with a slight twist.

Core Data will decide internally when to release the objects, so even if you are done with an object and you have released all of your references to it, it may stay around after that depending on what Core Data decides to do with it.

In addition, when a NSManagedObject is loaded into memory the entire object may not necessarily be loaded. Core Data, by default, will load the basic structure of the object but will not load in its data or relationships. This keeps the initial memory footprint very low. When you access a property then the entire instance will be fully realized.

The short answer is this: As long as you follow the retain release rules you do not need to worry about memory management with Core Data.


They are released when the retain count = 0 .

Unless you take ownership of them somehow they will vanish when the autorelease pool flushes. This is assuming you are creating them with... insertNewObjectForEntityForName:inManagedObjectContext:

The managed object context will still have the record but the NSManagedObject obeys the same retain/release rules as any other object. Think of NSManagedObject as a runtime container for the underlying data.

If you want to keep a hold of them use an NSArrayController for OS X or a NSMutableSet for UIKit are suggestions

0

精彩评论

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