MemoryManager.updateMemoryStatus()
kotlin.native.runtime.GC.collect()
timeStamp().also { timestamp->
runCatching {
CMSampleBufferGetImageBuffer(didOutputSampleBuffer).also { buffer ->
CVPixelBufferGetWidth(buffer).also { w ->
CVPixelBufferGetHeight(buffer).also { h ->
CIImage.imageWithCVPixelBuffer(buffer).also { imageBuffer ->
imageBuffer.toCGImageRef(w, h).also { cgImage ->
dispatch_queue_create(
"com.performancecoachlab.frameProcessing", null
).also { processingQueue ->
dispatch_async(processingQueue) {
frameProcessor.analyseFrame(
cgImage, timestamp
) { skeleton ->
... processing results here...
CGImageRelease(cgImage)
}
}
}
}
}
}
}
}
}
}
}
I have this code in a compose multiplatform which uses coreML to do realtime pose detection. It runs and works for a while but eventually I always get a badexec crash, sometimes quickly, sometimes it will run happily for an hour before crashing. My iOS experience is limited so I am not reall sure what I am doing when it comes to managing the memory, but I haven’t been able to figure out what I am doing wrong to cause this issue.
It is an open source project so you can see the full code here Making sure you're not a bot!