Question

I have a super basic AVCaptureSession set up with an AVCaptureVideoDataOutput and AVCaptureStillImageOutput. AVCaptureVideoDataOutput does not have a buffer delegate. There's nothing fancy going on, just setting up a standard issue AVCaptureSession. If I just compile the app and let it sit there for about 10 minutes, the available memory drops by like 1mb every minute or so. I've started the app with 72mb free, and after just letting it sit on my desk, I've seen free memory get as low as 33mb.

If I comment out the piece where I add AVCaptureVideoDataOutput to the session, available memory stays around 70-72mb.

So I set up a button to remove AVCaptureVideoDataOutput from the session, and after tapping the button, available memory immediately jumps back up to when the app was first run (~72mb). Has anyone else seen this and know of a workaround? I have iOS 5.0 on my iPhone and the latest beta SDK.

Edit: Here's the code that adds AVCAptureVideoDataOutput:


...

NSNumber *rgbNum = [NSNumber numberWithInt:kCVPixelFormatType_32BGRA];
NSDictionary *videoSettings = [NSDictionary dictionaryWithObject:rgbNum forKey:(id)kCVPixelBufferPixelFormatTypeKey];

dataOutput = [AVCaptureVideoDataOutput new];
[dataOutput setAlwaysDiscardsLateVideoFrames:YES];
[dataOutput setVideoSettings:videoSettings];
_videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", NULL);
[dataOutput setSampleBufferDelegate:self queue:_videoDataOutputQueue];
dispatch_release(_videoDataOutputQueue);

if ([session canAddOutput:dataOutput]) {
  [session addOutput:dataOutput];
} else {
  NSLog(@"couldn't add av data output");
}
...

Commenting out the buffer delegate doesn't seem to make a difference.

Just tried this again and it went from ~70mb free to ~54mb free within 6 minutes. :(

Was it helpful?

Solution 2

Apparently there's no workaround for this - filed a bug w/ Apple.

Edit: This question is a bit old, but in case it helps anyone: I'm not 100% positive, but I think the reason I was seeing this is because I had zombie objects turned on! Make sure you don't have zombie objects enabled in Xcode and see if that helps! Go to "Edit Scheme..." then choose the Diagnostics tab.

OTHER TIPS

I'm not sure you should care so much about current available memory in this case. iOS may cache something on it's own decision or keep memory reserved for some purposes.

To check memory leaks - it's better to use profiler with leaks tracker, but not just current memory available.

Also, it's good idea to check the behavior on released iOS SDK - the beta may have some issues since it's beta...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top