I'm still learning my way through iOS development and working with Core Data and have just come across retain cycles.
It is my understanding from reading the Core Data Programming Guide that after you're done working with a relationship, you use the managed object context method refreshObject:mergeChanges
to ensure that the retain cycle is broken.
So lets say I have a to-many relationship between a Department and its Employees, and in my code I access the employees relationship from department, does that mean I'll now need to loop through each employee object and call refreshObject:mergeChanges
method? In code this would be
for (Employee *anEmployee in department.employees) {
//some code that accesses an employee's properties
[context refreshObject:enEmployee mergeChanges:NO];
}
It seems that if I don't do that, each employee object I access will now contain a reference to the department and I will end up with retain cycles.
Is my understanding correct here? Is this a standard approach when dealing with to-many relationships in Core Data? Thanks.