2011-05-27 67 views
1

喂,我在iOS開發的新手,我已經endountered一些問題AVAssetWriter東西泄漏

我喜歡的對象AVAssetWriter的一些設置(我用它來寫pixelmaps 作爲幀視頻 - 和它的作品確定)

self.assetWriter = [[AVAssetWriter alloc] initWithURL:outputPath fileType:AVFileTypeQuickTimeMovie error:&error]; 

    NSMutableDictionary *dic=[[NSMutableDictionary alloc] init]; 
    [dic setValue: AVVideoCodecH264 forKey: AVVideoCodecKey]; 
    [dic setValue:[NSNumber numberWithInt:640] forKey:AVVideoWidthKey]; 
    [dic setValue:[NSNumber numberWithInt:480] forKey:AVVideoHeightKey]; 
    self.assetWriterInput = [[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeVideo outputSettings:dic]; 
     [dic release]; 

    assetWriterInputPixelBufferAdaptor =[[AVAssetWriterInputPixelBufferAdaptor alloc] initWithAssetWriterInput:assetWriterInput sourcePixelBufferAttributes:nil]; 

    self.assetWriterInput.expectsMediaDataInRealTime=YES; 
    [self.assetWriter addInput:assetWriterInput]; 

    [self.assetWriter startWriting]; 
    [self.assetWriter startSessionAtSourceTime:recordStartTime]; 

那麼之後我保存的視頻,然後後,我釋放實例

[self.assetWriterInput markAsFinished]; 
[self.assetWriter endSessionAtSourceTime:recordStartTime]; 
[self.assetWriter finishWriting]; 

CVPixelBufferPoolRelease(assetWriterInputPixelBufferAdaptor.pixelBufferPool); 
[self.assetWriter release]; 
[self.assetWriterInput release]; 
[self.assetWriterInputPixelBufferAdaptor release]; 

麻煩的是,儀器告訴我,當泄漏我使用上面的對幾次來創建和發佈實例來保存一些視頻

幫助!

+0

儀器中的泄漏痕跡是否表明泄漏與您的代碼有關?你有沒有對你的代碼進行靜態分析? – 2011-05-29 05:44:49

回答

0
AVAssetWriter *newWriter = [AVAssetWriter alloc] // retain count is 1. 
self.assetWriter = newWriter // What this actually does: 

- (void)setAssetWriter(AVAssetWriter*)newWriter 
{ 
    if (_assetWriter != newWriter) 
    { 
     [_assetWriter release] 
     _assetWriter = [newWriter retain]; //retain count 2 
    } 
} 

[self.assetWriter release]; //retain count 1 

如果您忘記添加self.assetWriter = nil; dealloc,你最終會泄漏。當[Alloc] ating實例並通過@properties分配它們時,附加autorelease以分配這樣的行:

self.assetWriter = [[[AVAssetWriter alloc] initWithURL:outputPath fileType:AVFileTypeQuickTimeMovie error:&error] autorelease]; 
+0

這些只是一個賦值屬性'@property(assign)AVAssetWriter * assetWriter; @property(assign)AVAssetWriterInput * assetWriterInput; @property(assign)AVAssetWriterInputPixelBufferAdaptor * assetWriterInputPixelBufferAdaptor;'所以我認爲這是關閉的問題(?) – fiery 2011-05-28 05:16:59