代码之家  ›  专栏  ›  技术社区  ›  Oded Ben Dov

AvCaptureStillImageOutputSetting内存泄漏

  •  3
  • Oded Ben Dov  · 技术社区  · 16 年前

    我在iPhone SDK的新AVFoundation类中遇到了wierd行为。

    我有一个AVCaptureStillImageOutput用于拍照,我正在根据自己的喜好设置它的输出设置。代码如下:

     AVCaptureStillImageOutput *stillImageOutput = [[[AVCaptureStillImageOutput alloc] init] autorelease];
    [stillImageOutput setOutputSettings:[NSDictionary dictionaryWithObject:AVVideoCodecJPEG forKey:AVVideoCodecKey]];
    [self setStillImageOutput:stillImageOutput];
    

    (stillImageOutput属性定义为“retain”)

    我无意中发现了一个漏洞,100%的漏洞都在 行。我相信,我只限于内存管理准则中所附的代码,它仍然在泄漏。

    [self.stillImageOutput setOutputSettings:nil];
    

    就在那之前

    [self setStillImageOutput:nil];
    

    泄漏确实停止了,但看起来很奇怪。难道不应该释放 静态图像输出 释放它 财产也是?

    不管怎样,如果有人遇到这种情况,我想我应该分享我的解决方案。

    干杯!
    奥德。

    1 回复  |  直到 16 年前
        1
  •  0
  •   Scott Corscadden    14 年前

    是的,释放stillImageOutput 释放它的outputSettings属性。要么是Apple的bug(应该让他们知道,你的用例很简单),要么删除你的代码行,看看除了你的类之外,是否还有其他东西挂在stillImageOutput对象上(它保存outputSettings)。