user3353890
user3353890

Reputation: 1891

Can someone provide clarification of "refreshObject:mergeChanges:YES" for me?

Let's say I have a "Person" NSManagedObject class:

class Person: NSManagedObject {
    NSManaged var name:String?
    NSManaged var bestFriend:Person?
}

How do I ensure that the reference to bestFriend as a "Person" doesn't create a strong reference cycle? I understand that you can use refreshObject:mergeChanges to manage strong references between CoreData objects and create faults so strong references don't persist. What I don't understand is when I use it, or where I call it. Do I use it after I first access the "Person" objects? Do I use it as I'm leaving a view? Before or after a save or delete? If someone could provide some clarification on this I would really appreciate it. Thank you very much!

Upvotes: 1

Views: 373

Answers (1)

Erik Johansson
Erik Johansson

Reputation: 1248

You will not have any issue with memory leaks (as far as I can understand), the only problem you might have is a bloated object graph which is stored in memory and needs to be "trimmed".

If you want to "trim" the object graph I suggest remove unused objects from the object graph when you are finished with them, otherwise they will just be faulted into the object graph again.

So use refreshObject:mergeChanges (with mergeChanges:false) whenever you are finished working with your Person and the bestFriend will be turned into a fault.

Upvotes: 1

Related Questions