cvRetrieveFrame memory leak using AVFoundation (Bug #1837)
Description
I'm getting a memory leak in this code:
@CvCapture* capture = cvCaptureFromFile([[url path] UTF8String]);
while (cvGrabFrame(capture)) {
IplImage *frame = cvRetrieveFrame(capture);
if (frame) {
[...]
} else {
break;
}
}
cvReleaseCapture(&capture);@
If I remove cvRetrieveFrame the memory leak disappears. If I change cvGrabFrame and cvRetrieveFrame with one cvQueryFrame the same behavior happens.
The behavior is the same with cvReleaseCapture enabled or commented out. So it's probably something related to that, but I can't figure out what.
On the second run on an iPhone 3GS sometimes I get :
serverConnectionDiedNotification. Info -- notification=Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo=0x1f1df330 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action}, AVPlayer = <MPQueuePlayer: 0x1f1756f0>, currentTime = 0.00
Or sometimes I get 2 frames instead of 20.
I'm using openCV r7286 on iOS.
Associated revisions
Fixed cvRetrieveFrame memory leak under AVFoundation (ticket #1837)
Merge pull request #1837 from asmorkalov:android_opencl
History
Updated by Radu Spineanu almost 13 years ago
This is the fix:
--- cap_avfoundation_old.mm 2012-04-23 04:01:02.000000000 0300
++ cap_avfoundation_new.mm 2012-04-23 04:01:11.000000000 +0300@ -968,6 +968,8
@
CVPixelBufferUnlockBaseAddress(pixels, 0);
CVBufferRelease(pixels);
+ CMSampleBufferInvalidate(sampleBuffer);
+ CFRelease(sampleBuffer);
[localpool drain];
return bgr_image;
Updated by Alexander Reshetnikov almost 13 years ago
Radu, your fix was applied in r8146.
- Status changed from Open to Done
- Target version set to 2.4.0
- Category changed from ios to highgui-images
- Assignee set to Alexander Reshetnikov
Updated by Radu Spineanu almost 13 years ago
Awesome!
Updated by Andrey Kamaev over 12 years ago
- Category changed from highgui-images to highgui-video