核心数据导入大量数据(Core Data import large amount of data)

编程入门 行业动态 更新时间:2024-10-28 11:24:47
核心数据导入大量数据(Core Data import large amount of data)

我的iOS应用程序首次运行时插入了大量实体。 我想知道在保存之前我可以在我的上下文中插入多少项? 我从Web调用中获取了一个大型JSON对象。 从JSON中我提取了大量实体并插入它们。

我该如何处理大量的插入?

谢谢

I am inserting a large amount of entities when my iOS app first runs. I am wondering how many items I can insert in my context before saving? I am getting a large JSON object from a web call. From the JSON I extract tons of entities and insert them.

How should I handle a large amount of insertions?

Thank you

最满意答案

zumzum,

将大量项目导入Core Data时需要担心许多问题。

第一个也是最重要的问题是管理内存。 大型JSON文档解析为大量小项。 这些会迫使您的常驻VM占用空间不可逆转地增长。 这种常驻足迹是应用程序被操作系统杀死的首要原因。 您可以拥有较小的已分配内存,但由于您的常驻足迹而仍然会被杀死。

因此,应该使用积极的中间内存清理操作分阶段处理大型文档。 使用并发MOC以及操作之间的重置是可行的方法。 然后我实现了一个尾随修剪模式来清理我的主线程MOC中保留的任何多余的内存。

安德鲁

zumzum,

There are many issues to worry about when importing a large number of items into Core Data.

The first and most important issue is managing memory. Large JSON documents parse into a huge number of small items. These force the irreversible growth of your resident VM footprint. This resident footprint is the number one reason apps are killed by the OS. You can have small size of allocated memory and still be killed due to the size of your resident footprint.

Hence, large documents should be processed in stages with aggressive intermediate memory cleanup operations. Using a concurrent MOC with resets between operations is the way to go. I then implement a trailing trimming pattern to clean up any superfluous memory retained in my main thread MOCs.

Andrew

更多推荐

本文发布于:2023-07-30 13:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1337903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   核心   Core   Data   data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!