且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将图像转换为视频时,iOS- CVPixelBufferCreate内存无法正确释放

更新时间:2023-02-17 14:34:13

通过快速检查您的代码,我看不到CVBuffer本身的管理中有什么问题.
我认为这可能是您的问题的来源是UIImages数组.
UIImage具有此行为,直到您请求CGImage属性或对其进行绘制之前,附加的图像不会在内存中解码,因此未使用的图像对内存的影响很小. 您的枚举在每个图像上调用CGImage属性,并且您永远不会摆脱它们,这可以解释内存分配的持续增加.

From a fast review of your code, I can't see anything wrong in the management of the CVBuffer itself.
What I think it could be the source of your issue is the array of UIImages.
UIImage has this behavior, until you request the CGImage property or draw it, the attached image is not decoded in memory, so the impact in memory of unused images is low.
Your enumeration calls the CGImage property on each image and you never get rid of them, this can explain the continue increase of memory allocation.