I am trying to do screen capturing and saving many images into NSMutableArray. Then, I will call those images and make video. I can successfully make video. However, the problem is that I can't save many images into NSMutableArray. The application crash. I would like to know how to save those images temporarily. (not in document directory).
我正在尝试做屏幕捕获并将许多图像保存到NSMutableArray中。然后,我将调用这些图像并制作视频。我可以成功制作视频。但是,问题是我不能将很多图像保存到NSMutableArray中。应用程序崩溃。我想知道如何暂时保存这些图片。(不是在文档目录)。
1 个解决方案
#1
1
You will quickly run out of memory if you try to store all of those images in an array. You have two options:
如果您试图将所有这些图像存储在一个数组中,您将很快耗尽内存。你有两个选择:
-
Even though you say you don't want to save all of those images to the Documents folder, that might be your best approach. Save them to Documents, and then have your video creation process load the images one at a time and add them to the video.
即使您说不想将所有这些图像保存到Documents文件夹中,这可能是您最好的方法。将它们保存到文档中,然后让视频创建过程一次加载一个图像,并将它们添加到视频中。
-
Alternatively, you can do the
renderInContext
of your view that you want to capture directly to theCGContextRef
that you've set up for yourCVPixelBufferRef
, do theappendPixelBuffer
, and but thenCVPixelBufferRelease
immediately.或者,您可以将视图的renderInContext直接捕获到为CVPixelBufferRef设置的cgcontext tref中,然后执行appendPixelBuffer,然后立即执行CVPixelBufferRelease。
Either of these approaches will avoid holding all of the images in memory at any given time, mitigating the out of memory situation. I profiled both approaches, and each avoids the constantly growing consumption of memory that the loading of images to an array suffers.
任何一种方法都将避免在任何给定的时间将所有映像保存在内存中,从而缓解内存不足的情况。我分析了这两种方法,每一种都避免了将图像加载到数组中所遭受的内存消耗的不断增加。
#1
1
You will quickly run out of memory if you try to store all of those images in an array. You have two options:
如果您试图将所有这些图像存储在一个数组中,您将很快耗尽内存。你有两个选择:
-
Even though you say you don't want to save all of those images to the Documents folder, that might be your best approach. Save them to Documents, and then have your video creation process load the images one at a time and add them to the video.
即使您说不想将所有这些图像保存到Documents文件夹中,这可能是您最好的方法。将它们保存到文档中,然后让视频创建过程一次加载一个图像,并将它们添加到视频中。
-
Alternatively, you can do the
renderInContext
of your view that you want to capture directly to theCGContextRef
that you've set up for yourCVPixelBufferRef
, do theappendPixelBuffer
, and but thenCVPixelBufferRelease
immediately.或者,您可以将视图的renderInContext直接捕获到为CVPixelBufferRef设置的cgcontext tref中,然后执行appendPixelBuffer,然后立即执行CVPixelBufferRelease。
Either of these approaches will avoid holding all of the images in memory at any given time, mitigating the out of memory situation. I profiled both approaches, and each avoids the constantly growing consumption of memory that the loading of images to an array suffers.
任何一种方法都将避免在任何给定的时间将所有映像保存在内存中,从而缓解内存不足的情况。我分析了这两种方法,每一种都避免了将图像加载到数组中所遭受的内存消耗的不断增加。