There some MTLTextures of which histogram is to be calculated, this textures changes at every loop iteration so calculation of histogram is carried out in loop using MPSImageHistogram
.
There is a single command queue on which a new command buffer is created at every loop iteration to perform histogram calculation.
Memory footprints (from allocation instrument) keeps on increasing due to new command buffer creation in the loop.
The question is how to clear the allocated memory of the command buffer once it's executed? Or is there any way for restructuring the calculation scheme?
In short, how to deallocate the memory consumed by metal objects like command buffer, compute pipeline, encoders etc.
I would suggest looking at autoreleasepool
. It is intended to be used for iterations, it frees memory each loop.
Supposing your render function is called performHistogram
you can do something like this:
var myTexture: MTLTexture? = nil
autoreleasepool {
myTexture = performHistogram()
}
//myTexture has been updated and memory should be freed.