【发布时间】:2014-06-12 18:19:28
【问题描述】:
我每分钟都会使用核心数据对我的 sqlite 数据库进行更新,方法是发出 Web 请求、解析该请求并更新我的托管对象上下文中的对象。 从网络服务器返回的 JSON 数据存储在 NSDictionary 中:
NSDictionary* dictionary = [NSJSONSerialization JSONObjectWithData:operation.data options:kNilOptions error:&error];
我使用存储为成员的字典初始化一个 NSOperation 实例。该操作循环遍历字典并更新一个 NSManagedObjectContext,例如:
for (NSDictionary *item in self.dictionary) {
NSManagedObject *newItem = [NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:self.context];
[newItem setValue:item[@"customerName"] forKey:@"contact_firstname"];
}
[self.context save:&error];
查看仪器面板,我发现每次更新都会留下一些未发布的 CFString 对象:
已发布和未发布的 CFString 之间的差异可以通过每个的 refcount 跟踪来显示:
已发布
未发布:
[NSManagedObject(_NSInternalMethods) _newAllPropertiesWithRelationshipFaultsIntact__] 的保留 (+1) 可防止该对象被释放。由于每次更新我都会从 MSManagedObjectContext 中删除所有对象,因此我看不出有什么理由不应该释放这些 CFString。
_newAllPropertiesWithRelationshipFaultsIntact__ 的用途是什么,为什么它会保留我的一些 CFStrings?
【问题讨论】:
-
你有没有深究过这个?
标签: ios core-data ios7 memory-leaks instruments