Core Data And Retain Cycles

前端 未结 1 615
小蘑菇
小蘑菇 2021-01-02 21:58

I have a core data class Game which has a to-many relationship to another class Player. This is what their headers look like

@property (nonatomic, retain) NS         


        
相关标签:
1条回答
  • 2021-01-02 22:16

    See Core Data Programming Guide: Memory Management (Breaking Relationship Retain Cycles).

    When you have relationships between managed objects, each object maintains a strong reference to the object or objects to which it is related. In a managed memory environment, this causes retain cycles (see Object Ownership and Disposal) that can prevent deallocation of unwanted objects. To ensure that retain cycles are broken, when you're finished with an object you can use the managed object context method refreshObject:mergeChanges: to turn it into a fault.

    You typically use refreshObject:mergeChanges: to refresh a managed object's property values. If the mergeChanges flag is YES, the method merges the object's property values with those of the object available in the persistent store coordinator. If the flag is NO, however, the method simply turns an object back into a fault without merging, which causes it to release related managed objects. This breaks the retain cycle between that managed object and the other managed objects it had retained.

    0 讨论(0)
提交回复
热议问题