6

I am using AVFoundation framework to capture video with iPhone camera, my codes:

 self.session = [[AVCaptureSession alloc] init];
 ...
 self.output = [[AVCaptureVideoDataOutput alloc] init];
 [self.session addOutput:self.output];

Before [session addOutput], everything goes well, memory is limited to 3M, but after [session addOutput], memory usage increase 0.06M per second, after some minutes, the App will crash because of memory warning. AVCaptureVideoDataOutput seems cost too much memory, and maybe have a memory leak issue.

So how can i to reduce the memory usage?

iOS version: 7.1.1

Aloha Silver
  • 1,394
  • 17
  • 35
  • 2
    Do you have zombies enabled? – Abhi Beckert May 07 '14 at 03:48
  • I am having the same problem, did you solve this problem? If yes, please share your solution. – Asif Bilal Mar 18 '19 at 12:26
  • Do `[self.session addOutput:self.output];` in the main queue. – Onur Tuna Mar 18 '19 at 14:47
  • Did you find a solution to this problem? I'm currently experiencing the same issue: https://stackoverflow.com/q/67370456/5281431 – mrousavy May 03 '21 at 14:17
  • Had the same problem. Anybody found the reason? – Jenny Tran Feb 28 '22 at 10:05
  • As @Gajendra mentioned below, I messed around with the `AVCaptureSession` session preset. using `.high` still cost me too much memory. I tried using `.medium` and significantly reduced the memory consumption and CPU usage, but the video quality is greatly reduced as well. I ended up trying using. the `.hd1280x720` preset and it doesn't use that much RAM and CPU usage but still had a pretty good quality. – cleanrun Jan 29 '23 at 10:01

1 Answers1

1
AVCaptureSession *mSession; ;

use session preset heigh instead of session preset photo

mSession.sessionPreset = AVCaptureSessionPresetHigh; //yes

mSession.sessionPreset = AVCaptureSessionPresetPhoto; //no
Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36