I have recently noticed that if I fetch a ManagedObject of which I can verify that there is only one in the model and which is not retained anywhere in my application, every time the fetch returns the object it is a different instance (with a pointer to a different memory adress). Why is this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If no one retains it, Core Data is free to release it. If you ask for it again, it will probably be at a different memory location. You can't count on it being the same object instance.
回答2:
A given NSManagedObject
is tied to a specific NSManagedObjectContext
, so if you change contexts, you will necessarily change objects. If the object faults, you may also receive a new instance if the MOC has released the object. This is part of how Core Data keeps memory usage low.