Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should Reference to Core Data Object be Strong or Weak?

I couldn't think of core data refer to anything outside coredata. So there is no way there will be reference cycle. At most core data object points to another coredata objects.

however, I may be wrong.

Managedobjectcontext do not hold strong reference to core data.

Is there any guide here?

like image 612
Septiadi Agus Avatar asked Jan 26 '26 21:01

Septiadi Agus


1 Answers

Is there any guide here?

Here is a link to Core Data Programming Guide: Object Lifetime Management.

It was updated on July 2014, so it may have new information not published when you asked this question.

By default, though, the references between a managed object and its context are weak. This means that in general you cannot rely on a context to ensure the longevity of a managed object instance, and you cannot rely on the existence of a managed object to ensure the longevity of a context. Put another way, just because you fetched an object doesn’t mean it will stay around.

The exception to this rule is that a managed object context maintains a strong reference to any changed

This means your references to NSManagedObject subclasses (Core Data objects) should be strong.

like image 140
Jeff Avatar answered Jan 28 '26 11:01

Jeff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!