本文介绍了如何在iOS 8 Photo Extensions中处理内存限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在现有的照片编辑应用程序中添加了一个新的iOS 8 Photo Extension。我的应用程序有一个非常复杂的过滤器管道,需要一次在内存中保留多个纹理。但是,在具有1 GB RAM的设备上,我可以轻松处理8 MP图像。

I added a new iOS 8 Photo Extension to my existing photo editing app. My app has quite a complex filter pipeline and needs to keep multiple textures in memory at a time. However, on devices with 1 GB RAM I'm easily able to process 8 MP images.

然而,在扩展中,存在更高的内存限制。我不得不将图像缩小到2 MP以下,以便在不破坏扩展名的情况下对其进行处理。我还认为只有在未将扩展调试器附加到调试器时才会出现内存问题。有了它,一切正常。

In the extension, however, there are much higher memory constraints. I had to scale down the image to under 2 MP in order to get it processed without crashing the extension. I also figured that the memory problems only occurred when not having a debugger attached to the extension. With it, everything works fine.

我做了一些实验。我修改了以在扩展中工作,并得出以下结果(显示金额)可以在崩溃前分配的MB的RAM):

I did some experiments. I modified a memory budget test app to work within an extension and came up with the following results (showing the amount of RAM in MB that can be allocated before crashing):

╔═══════════════════════╦═════╦═══════════╦══════════════════╗
║        Device         ║ App ║ Extension ║ Ext. (+Debugger) ║
╠═══════════════════════╬═════╬═══════════╬══════════════════╣
║ iPhone 6 Plus (8.0.2) ║ 646 ║       115 ║              645 ║
║ iPhone 5 (8.1 beta 2) ║ 647 ║        97 ║              646 ║
║ iPhone 4s (8.0.2)     ║ 305 ║        97 ║              246 ║
╚═══════════════════════╩═════╩═══════════╩══════════════════╝

一些观察结果:


  • 附加调试器后,扩展程序的行为类似于普通应用程序

  • 尽管4s只有一半的内存总量(512 MB),但与其他设备相比却相同〜来自系统的100 MB扩展名。

现在我的estion:我如何在照片编辑扩展程序中使用这么少的内存?一个包含8 MP(相机分辨率)RGBA图像的纹理单独吃~31 MB。如果我必须告诉用户只有在使用主应用程序时才能进行全尺寸编辑,这个扩展机制有什么意义呢?

Now my question: How am I supposed to work with this small amount of memory in a Photo Editing extension? One texture containing an 8 MP (camera resolution) RGBA image eats ~31 MB alone. What is the point of this extension mechanism if I have to tell the user that full size editing is only possible when using the main app?

你们其中一个人是否也达到了这个目标屏障?您是否找到了解决此约束的解决方案?

Did one of you also reach that barrier? Did you find a solution to circumvent this constraint?

推荐答案

我正在为我的公司开发照片编辑扩展程序,我们正面临同样的问题。我们的内部图像处理引擎需要超过150mb才能将某些效果应用于图像。这甚至不计算全景图像,每个副本大约需要100mb的内存。

I am developing a Photo Editing extension for my company, and we are facing the same issue. Our internal image processing engine needs more than 150mb to apply certain effects to an image. And this is not even counting panorama images which will take around ~100mb of memory per copy.

我们发现只有两个解决方法,但不是一个实际的解决方案。

We found only two workarounds, but not an actual solution.


  1. 缩小图像,然后应用滤镜。这将需要更少的内存,但图像结果是可怕的。至少延期不会崩溃。


  1. 使用CoreImage或Metal进行图像处理。我们分析了Apple的 ,使用CoreImage,可以处理非常大的图像甚至全景图,没有质量或分辨率损失。实际上,我们无法通过加载非常大的图像来破坏扩展。示例代码可以处理具有40mb内存峰值的全景图,这非常令人印象深刻。

  1. Use CoreImage or Metal for image processing. As we analyzed the Sample Photo Editing Extension from Apple, which uses CoreImage, can handle very large image and even panoramas without quality or resolution loss. Actually, we were not able to crash the extension by loading very large images. The sample code can handle panoramas with a memory peek of 40mb, which is pretty impressive.

根据Apple的,第55页,处理内存约束一章,扩展中内存压力的解决方案是检查图像处理代码。到目前为止,我们正在将我们的图像处理引擎移植到CoreImage,结果远远优于我们以前的引擎。

According to the Apple's App Extension Programming Guide, page 55, chapter "Handling Memory Constraints", the solution for memory pressure in extensions is to review your image-processing code. So far we are porting our image processing engine to CoreImage, and the results are far better than our previous engine.

我希望我能帮上忙。
Marco Paiva

I hope I could help a bit.Marco Paiva

这篇关于如何在iOS 8 Photo Extensions中处理内存限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 16:45