如何使用Core Data External Storage释放内存? [英] How to free memory using Core Data External Storage?

查看:74
本文介绍了如何使用Core Data External Storage释放内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果文件很大,核心数据可以使用外部存储来存储二进制数据。

Core Data can store binary data using External Storage if the file is large.

我正在使用该外部存储来存储图像并将其显示在<$中c $ c> UITableView 。
之前,我需要调整这些图像的大小以适合UI的大小。
因此,我将内存中的 NSData 属性保存在获取的对象并调整了图像的大小。

I'm using that External Storage to store images and show them in a UITableView. Before, I need to resize theses images to fit the size in the UI. So, I'm keeping in memory NSData properties from objects fetched and image resized.

Are有什么方法可以解决此内存问题?还是这种方法是错误的?

Are there ways to handle this memory issue? or this approach is wrong?

谢谢。

推荐答案

您可以使用NSManagedObjectContext的:-refreshObject:mergeChanges:传递 NO 作为第二个参数,这会将对象转回故障使用完数据后。

You can use NSManagedObjectContext's: - refreshObject:mergeChanges: passing NO as the second parameter, this will turn the object back into a fault after you have used the data.

这样,您可以获取图像,根据需要调整大小,缓存该图像,然后使ManagedObject放弃数据

This way, you can get the image, resize it however you want, cache this image and then fault the ManagedObject to give up the data.

这篇关于如何使用Core Data External Storage释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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