Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-29-2010, 08:19 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Location: Seattle, WA
Posts: 13
zenchemical is on a distinguished road
Default Memory "Leaks" using AVCaptureSession

I just solved a somewhat non-obvious issue with using AVCaptureSession to capture live video. I had what I thought was a memory leak, but it turned out not to be...well, sort of.

The structure of the code was roughly:

* set up session with AVCaptureSession
* set up delegate captureOutput to grab & convert the image, do a little bit of fiddling with it, and exit

Pretty straightforward, but what was happening in instruments is that the CGDataProvider object was growing astronomically, and after about 3 minutes the app would crash.

After several other tests, I surmised that this is actually the queue filling up, so what I did as a solution looked roughly like this:

each frame:

// now push an async task to tell us when we're done
proctr++;
if ((proctr % 20) == 0){
deferImageProcessing = true;
dispatch_sync(queue, ^{
[self queueFlushed];
});
}

- (void)queueFlushed {
deferImageProcessing = false;
}

Effectively, each 20th processed frame, we suspend output, send a little message through the queue, and un-suspend output when it's received. If the queue is empty, this will have no effect,since it will take one frame. If it's not empty, though, it might take a few frames to clear out. Obviously you can adjust the modulus intelligently (probably something near the frame rate)

Then it's just a matter of skipping the updates inside the delegate:

- (void)captureOutputAVCaptureOutput *)captureOutput didOutputSampleBufferCMSampleBufferRef)sampleBuf fer fromConnectionAVCaptureConnection *)connection
{
if (deferImageProcessing)
return;

// fiddle with image, update live image, whatever you're doing...
}

-Sean
zenchemical is offline   Reply With Quote
Reply

Bookmarks

Tags
capture, leak, memory, video

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 343
7 members and 336 guests
headkaze, mistergreen2011, nobstudio, Objective Zero, rayjeong, revg, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:10 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0