gpt4 book ai didi

ios - AVAssetWriter 东西泄露

转载 作者:行者123 更新时间:2023-11-28 17:45:39 31 4
gpt4 key购买 nike

你好,我是 ios 开发的新手,我遇到了一些问题

我做了一些 AVAssetWriter 的设置,比如对象(我用它来写像素图作为视频的帧 - 它工作正常)

    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];

问题是,当我多次使用上述对创建和释放实例以保存几个视频时,Instruments 向我显示泄漏

帮助!

最佳答案

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;去分配,你最终会泄漏。当 [Alloc]ating 实例并通过 @properties 分配它们时,将 autorelease 附加到 alloc 行,如下所示:

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

关于ios - AVAssetWriter 东西泄露,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6156917/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com