NSFetchedResultController 问题
我目前正在使用 NSFetchedResultController 来获取显示的数据。 不过我有两个问题:
1)当我将 fetchSizeBatch 属性设置为 2 时,我的应用程序总是崩溃。 fetchSizeBatch 的实际含义是什么?我真的不想将其设置为 2,我只是在玩它并注意到了该错误。
2) 我的应用程序当前在滚动 UITableView 时使用大约 25 MB 的内存。我认为 NSFetchedResultController 是造成这种情况的原因。 25MB还正常吗?或者这个控制器是某种指定的设备?
I'm currently using NSFetchedResultController to get the to displayed data.
However I've got two question about it:
1) When I set the fetchSizeBatch property to 2, my app always crashes.
What does fetchSizeBatch actually mean? I don't really want to set it to 2, I was just playing with it and noticed that bug.
2) My app currently uses about 25 MB of memory while scrolling through the UITableView. I assume NSFetchedResultController is causing that. Is 25 MB still normal? Or is this controller some sort of device specified?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于核心数据批量大小而言,2 是一个极低的数字。 根据文档,它可能比我解释得更好,设置批量大小意味着数据将在批次;换句话说,Core Data 查询数据库以获取排序结果,但仅将批量大小指定的数量拉入托管对象。这个的实现 - 这是最重要的部分 - 是 NSArray 的代理子类,每当访问每个批次的项目时,无论是通过索引、枚举还是其他方式,它将分页。在您的例子中,这意味着 Core Data 每两个对象就会往返一次数据库。对于与 UITableView 通信的 NSFetchedResultsController,您可以看到这是一个多么严重的问题。
否则,25MB 并不理想,但我见过应用程序的表现更糟糕。我想说你很好。
Two is an extremely low number for a Core Data batch size. According to the documentation, which probably explains it much better than I do, setting a batch size means that the data will be processed in batches; in other words, Core Data queries the database for the sorted results but only pulls the amount specified by the batch size into managed objects. The implementation of this - and this is the big part - is a proxy subclass of NSArray which will page in items from each batch whenever they're accessed, either by index, enumeration, whatever. In your case, this means that Core Data is taking a round trip back to the database every two objects. For an NSFetchedResultsController talking to a UITableView, you can see how much of a problem this is.
Otherwise, 25MB isn't fantastic, but I've seen apps do much worse. I would say you're good.