建议:在内存不足的情况下我应该考虑[NSManagedObjectContext重置]吗?
当我收到内存不足警告时,我应该考虑在我的 NSManagedObjectContext
上调用 reset
吗?使任何指向 NSManagedObject
的指针无效会有点困难,但如果这是正确的做法,我会处理它!
或者核心数据库是否会排除NSManagedObject
对象以减少其实时内存大小?
我应该提到的是,这个上下文是在应用程序委托中创建的,因此通常存在于整个应用程序生命周期中。我在后台线程中也有上下文,但是当线程结束时,这些上下文会被 dealloc'd() 。
Is calling reset
on my NSManagedObjectContext
something I should consider doing when I get a low memory warning? It would be a bit difficult to invalidate any pointers to NSManagedObject
's that were hanging around, but I'd handle that if its the right thing to do!
Or will the core data libraries fault out the NSManagedObject
objects to reduce their live memory size?
I should mention that this context is created in the App Delegate and so generally lives for the entire application lifecycle. I also have context's in background threads but these get dealloc'd() when the thread ends.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Core Data 监听低内存警告,并尝试通过清除缓存、在它认为可能的情况下排除对象等方式采取行动。
在我看来,这是使用 Core Data 而不是滚动自己的对象持久层的重要原因之一。
Core Data listens for low memory warnings, and will attempt to take action by clearing caches, faulting objects out where it deems that possible, and so on.
In my opinion it's one of the strong reasons to use Core Data rather than rolling your own object persistence layer.