我可以清除受管对象上下文吗? [英] Can I clear the Managed Object Context?

查看:102
本文介绍了我可以清除受管对象上下文吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我在做一个真正大的导入,我解析一个XML文件。对于每10个解析的托管对象,我想保存托管对象上下文并删除这10个对象在内存中,所以我从来没有超过10个对象在内存中一次。

Problem: I am doing a really big import where I parse an XML file. For every 10 parsed managed objects, I want to save the Managed Object Context and get rid of those 10 objects in memory, so that I have never more than 10 objects in memory at a time.

保存之后,如何清除上下文,使所有对象都离开内存?

After saving it, how could I clear the context so that all the objects go away from memory?

推荐答案

在这种情况下,有四件事要记住要做:

In a situation like this there are four things to remember to do:


  1. 将你的循环包装在 NSAutoreleasePool

  2. 定期保存上下文;然后

  3. 使用-reset重置上下文

  4. 释放并重新创建自动释放池

  1. Wrap your loop in a NSAutoreleasePool
  2. Periodically save the context; then
  3. Reset the context with -reset
  4. Release and re-create the autorelease pool

这将刷新所有正在使用的内存并清除上下文。

This will flush all of the memory being used and clear the context.

这篇关于我可以清除受管对象上下文吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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