Bound Buffer Memory Leak

Hi - not sure this is strictly a metal issue, but I'm having problems with a memory leak.

When I create a buffer to use with the GPU, then bind the results so that I can access the data, the created buffer seems to stay in memory even once the variables intensityPointer and intensityBuff is no longer in scope.

I tried using deallocate, but this caused an error too.

Is there a standard way of managing such memory, or accessing the buffer in a different way which will allow the memory to be released when no longer used?

Thank you,

Colin

let intensityBuff = myGPUData.device?.makeBuffer(length: MemoryLayout<Float>.stride * Int(myStars.nstars * myStars.npatch * myStars.npatch, options: .storageModeShared)

let intensityPointer = intensityBuff?.contents().bindMemory(to: Float.self,                                                       capacity: MemoryLayout<Float>.stride * Int(myStars.nstars * myStars.npatch * myStars.npatch))

I am guessing that you want a tighter autorelease pool block. You can add one at a tighter scope to drain released objects e.g. autoreleasepool { <your code> }

Thank you very much - that solved the problem. I hadn't come across autoreleasepool before - reading up on this, this needs to be used if objects are created based on older (Objective-C based) frameworks.

Thank you again.

Colin

Bound Buffer Memory Leak
 
 
Q