0

One simple straight question, when to release source pixelbuffer after transferred image to avoid crash:

//pixel_buffer is the original 
CVPixelBufferCreate(kCFAllocatorDefault, 
     CVPixelBufferGetWidth(pixel_buffer), 
     CVPixelBufferGetHeight(pixel_buffer), 
     kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, 
     NULL, &targetPxb);

if (targetPxb != NULL) {
     auto status = VTPixelTransferSessionTransferImage(transSession, 
                           pixel_buffer, 
                           targetPxb);
     if (status == noErr) {
           //  CFRelease(pixel_buffer); //this will cause crash
     }
}
Steven
  • 468
  • 4
  • 14

1 Answers1

0

Check the reference count of pixel_buffer. If you did not add a CFRetain, executing a CFRelease will cause your application to crash since the reference count is already 0, so there is no need to call CFRelease in this case. There are simple ways of checking the reference count, for example:

CFGetRetainCount