Core Data如何确定是否可以删除NSObjects数据? [英] How does Core Data determine if an NSObjects data can be dropped?

查看:74
本文介绍了Core Data如何确定是否可以删除NSObjects数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的应用程序中,我在Core Data中存储了大约500张图片。我已经把这些图像出来,并将它们存储在文件系统中,但在这个过程中,我发现应用程序将崩溃在设备上,如果我有一个500对象与图像数据的数组。具有500个对象标识符的数组,这些对象中的图像数据工作正常。没有图像数据的500个对象也工作正常。我发现我得到了最好的性能与一个数组的对象ID和图像数据存储在文件系统,而不是在核心数据。

In the app I am working on now I was storing about 500 images in Core Data. I have since pulled those images out and store them in the file system now, but in the process I found that the app would crash on the device if I had an array of 500 objects with image data in them. An array with 500 object ids with the image data in those objects worked fine. The 500 objects without the image data also worked fine. I found that I got the best performance with both an array of object ids and image data stored on the filesystem instead of in core data.

我得到的结论是,如果我有一个对象在一个数组告诉Core Data我是使用该对象和Core Data将持有数据。

The conclusion I came to was that if I had an object in an array that told Core Data I was "using" that object and Core Data would hold on to the data. Is this correct?

推荐答案

简短的答案是肯定的。

长的答案是它取决于图像的大小。规则是:

The long answer is that it depends on the size of the images. The rule is:


  • 小于100kb存储在主表中。

  • 小于1mb将其存储在关系另一端的辅助表中。

  • 大于1mb,将其存储在磁盘上,并通过文件路径引用它。

因此,根据文件的大小将决定在哪里存储它们。另外,请记住,UIImage处理缓存,因此您可能不需要将图像存储在数组中。

So, depending on the size of your files will determine where to store them. Also, keep in mind that UIImage handles caching so you may not need to store the images in an array at all.

你的问题不清楚。您不需要将图像存储在数组中,因为A)图像正由单元格保存; B)UIImage将缓存您的映像,所以如果最近访问它将不会从磁盘检索。因此,您不必要地强制保留图片。

Your question is unclear then. You do not need to store the images in an array because A) the image is being held by the cell and; B) UIImage will cache the image for you so it will not be retrieved from disk if it has been accessed lately. So you are forcing the retention of images unnecessarily.

对于Core Data本身,它会根据需要删除内存中的属性。当访问时,它会自动将它们拉回内存。 Core Data还缓存数据,所以你不应该看到任何性能问题,因为在内存中移动。

With regard to Core Data itself, it will drop attributes out of memory as needed as well. It will automatically pull them back into memory when accessed. Core Data also caches the data so you should not see any performance issues there either as things are being moved around in memory.

这篇关于Core Data如何确定是否可以删除NSObjects数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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