iphone - UIImage 在低内存情况下如何工作?

标签 iphone memory-management uiimage

根据UIImage documentation :

In low-memory situations, image data may be purged from a UIImage object to free up memory on the system.

有人知道这是如何工作的吗?看来这个过程是完全透明的,并且将在后台发生,不需要我的任何输入,但我无法以某种方式找到任何明确的文档。

第二,当我没有加载图像时,会发生这种数据清除吗? (我从 UIImagePicker 获取图像)。

情况如下:我正在使用 UIImagePickerController 拍照,并立即拍摄该图像并将其发送到新的 UIViewController 进行显示。将原始图像发送到新 Controller 会使我的应用程序崩溃,并在大约 30% 的情况下出现内存警告。调整图像大小需要一些时间,如果有第三个选项可供我使用,我宁愿不花这些时间。

最佳答案

我想这就是答案。在 initWithContentsOfFile: 的文档中,它说:

This method loads the image data into memory and marks it as purgeable. If the data is purged and needs to be reloaded, the image object loads that data again from the specified path.

UIImage 中的其他方法都没有提到清除,因此看来从文件初始化新图像是获得这种低内存行为的唯一方法。

关于iphone - UIImage 在低内存情况下如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2496714/

相关文章:

iphone - 限制对 iPhone 应用程序的 Web 服务访问

iOS - Symbolicate 堆栈跟踪符号

php - 如何获得可供 PHP 使用的内存

ios - "Received memory warning"在 ios 中使用 NSThread 时

iphone - 是否可以以编程方式反转图像的颜色?

swift - 合并图像和文本在 swift 4 中创建另一个图像

iphone - 具有数千个对象的 NSDictionary 会很慢吗?

iphone - 在 ipad 中测试 iphone 应用程序?

c++ - 在 C++ 中调用 free() 在调试中触发 ntdll!DbgBreakPoint() 但在发布时崩溃

objective-c - UIImageView setImage 不起作用