I try to make some histogram calculations using vImage buffers in Accelerate framework and I supply camera image as UIimage converted from CVpixelbuffer. Algorithm works with no error however processed camera image data on the screen is very slow. I read some info in Apple documentation about freeing the buffers when task is completed. I wrote two lines of code after grab the buffer data. However nothing changes. Please see attached screenshot of buffers data after they are freed.SourceBuffer and histogramSourceBuffer are seems not freed. I don't know how a free buffer has to be seen in debugger but mine are shown with height, width and data info. Any recommendation how to free the buffer and how can I ensure it is freed. Many thanks indeed
if let finalImage = try? sourceBuffer.createCGImage(format: format) {
sourceBuffer.free()
histogramSourceBuffer.free()
return UIImage(cgImage: finalImage)
You need to call free() on the vImage_Buffer.data pointer to free the memory. The struct itself is a different allocation.
The histogram itself is an array of pointers to arrays of vImagePixelCounts. That should be freed according to how you allocated the arrays of vImagePixelCounts. vImage isn't involved in that part, so it is between you and you.