2

The core data guidelines recommend that you model your relationships with an inverse. No problems there.

Interestingly though if you Load an object A that has a to many relationship to B and walk the object graph you end up with a retain cycle and the memory is never freed.

For a simple object graph you can just call refreshObject:mergeChanges: on A to re-fault the object so that relationships are no longer strong references.

If you have a complicated object graph though this is a pain because you need to call it on every object you have touched. It seems like a pretty important consideration when using core data yet there is only one paragraph on this topic in Apples documentation.

I am just wondering how other people handle this? A long running app would slowly just consume more and more memory without some sort of manual process to force objects to revert to faults.

Are there any known patterns for dealing with this. I'd imagine so since lots of people use Core Data I just can't find any recommendations

4

1 回答 1

1

在做出断言时,您忽略了核心数据的几个方面。如果您获取一个对象,假设对象 A 与对象 B 具有一对多关系,当您获取 A 时,您将拥有 B 上与 A 相关的所有对象。一对多关系创建与 A 相关的对象列表,并将它们包含在 NSManagedObject 子类的 NSSet 属性中。请注意,这些对象处于故障状态,并且由此产生的内存占用是微不足道的。如果您操作关系中的对象,核心数据将在必要时对这些对象进行无故障处理。您无需执行任何操作即可获得此行为。如果您想自己触发故障行为以再次将对象发送到故障,您可以使用 refreshObject:mergeChanges:。如果你不把它们送回故障,

于 2012-10-12T16:25:20.420 回答