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
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 themergeChanges
flag isYES
, the method merges the object's property values with those of the object available in the persistent store coordinator. If the flag isNO
, 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.