每次我获取同一个 NSManagedObject 时,Core Data 都会返回一个不同的对象实例.为什么是这样? [英] Core Data returns a different object instance for the same NSManagedObject each time I fetch it. Why is this?

查看:24
本文介绍了每次我获取同一个 NSManagedObject 时,Core Data 都会返回一个不同的对象实例.为什么是这样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近注意到,如果我获取一个 ManagedObject ,我可以验证模型中只有一个并且没有保留在我的应用程序中的任何位置,每次获取返回对象时它都是一个不同的实例(使用指向不同内存地址的指针).这是为什么呢?

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?

推荐答案

如果没有人保留,Core Data 可以自由发布.如果您再次要求它,它可能会位于不同的内存位置.你不能指望它是同一个对象实例.

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.

这篇关于每次我获取同一个 NSManagedObject 时,Core Data 都会返回一个不同的对象实例.为什么是这样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆