Master data and save cycles

I have a game with a base data class that is related to many to another Player class. This is what their headlines look like

@property (nonatomic, retain) NSSet * players; // In Game.h @property (nonatomic, retain) Game * game; // In Player.h (the inverse relationship) 

When I release the last external link that I have in the Game class, didTurnIntoFault is not called. Now, my question is that this may be due to the circular link created above (as you can see, both properties are β€œsaved”), or the main data controls all of this, and the problem is somewhere in my code.

+6
core-data
source share
1 answer

See Master Data Programming Guide: Memory Management (Maintaining Communication Retention Cycles) .

When you have a relationship between managed objects, each object maintains a strong reference to the object or objects with which it is associated. In a managed memory environment, this causes retention cycles (see "Ownership and Deletion of Objects" ), which can prevent the release of unwanted objects. To ensure that save cycles are preserved when you are done with the object, you can use the refreshObject:mergeChanges: managed object context method to include it in the fault.

Usually you use refreshObject:mergeChanges: to update the values ​​of the properties of the managed entity. If the mergeChanges flag is YES , the method combines the property values ​​of the object with the objects available in the persistent storage coordinator. However, if the flag is NO , the method simply turns the object back into an error without merging, which forces it to release related managed objects. This breaks the save cycle between this managed entity and the other managed entities that it has saved.

+4
source share

All Articles