从托管对象上下文中删除后,使用保留的NSManagedObject是否安全? [英] Is it safe to use a retained NSManagedObject after removal from managed object context?

查看:40
本文介绍了从托管对象上下文中删除后,使用保留的NSManagedObject是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSManagedObject,它仅具有属性(没有获取的属性或Relationshiops)。我保留实例,告诉托管上下文从图中删除对象,然后保留托管上下文。

i have an NSManagedObject that has just attributes(no fetched properties or relationshiops). I retain the instance, tell the managed context to remove the object from the graph, i persist the managed context.

从数据库中删除对象后使用实例是否安全?受管理的上下文?

is it safe to use the instance after the removal from the managed context?

分步进行:

->retain NSManagedObject
->remove NSManagedObject from managed object context
->persist changes to the managed object context
->use NSManagedObject


推荐答案

我不这么认为。 NSManagedObject属于商店。您使用商店来创建和销毁它。如果您决定执行其他操作,请务必谨慎,因为正如NSManagedObject文档所述,重要的是要记住,Core Data保留了对受管对象(即原始内存管理)生命周期的排他控制。

I don't believe so. A NSManagedObject belongs to the store. You use the store to create and destroy it. Be very cautious if you decide to do otherwise because as the NSManagedObject docs say, "it is important to remember that Core Data reserves exclusive control over the life cycle of the managed object (that is, raw memory management)."

->remove NSManagedObject from managed object context

$ b $中删除NSManagedObject b

这是否意味着该对象仍然被释放?当然,从那时起,您可以忽略它而不会泄漏。

Doesn't this imply that the object is released anyway? Certainly you can ignore it from then on without leaking.

因为您有一个仅带有属性的简单对象,如果需要保留它们,只需复制它们即可。

Because you have a simple object with only attributes just copy them if you need to keep them around.

这篇关于从托管对象上下文中删除后,使用保留的NSManagedObject是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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