gpt4 book ai didi

iPhone - 收到内存警告

转载 作者:行者123 更新时间:2023-12-03 21:03:20 25 4
gpt4 key购买 nike

我正在使用 aVFoundation 框架从视频资源中读取 CMSampleBufferRef,在一个 while 循环中我得到了如下所示的图像:

-(void)splitImagesFromVideo
{
if (images != nil) {
[images release];
images = nil;
}
images =[[NSMutableArray alloc] init];


NSURL *fileURL = [[NSBundle mainBundle]
URLForResource:@"3idiots" withExtension:@"mov"];

NSLog(@"video: %@",videoURL);

AVAsset *theAVAsset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];

NSError *error = nil;
float width = theAVAsset.naturalSize.width;
float height = theAVAsset.naturalSize.height;
AVAssetReader *mAssetReader = [[AVAssetReader alloc] initWithAsset:theAVAsset error:&error];



NSArray *videoTracks = [theAVAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *videoTrack = [videoTracks objectAtIndex:0];


NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
AVAssetReaderTrackOutput* mAssetReaderOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:options];

[mAssetReader addOutput:mAssetReaderOutput];



BOOL success = [mAssetReader startReading];
NSInteger val = 1;

while ( [mAssetReader status]==AVAssetReaderStatusReading ){
CMSampleBufferRef buffer = [mAssetReaderOutput copyNextSampleBuffer];//read next image.
if (buffer) {

UIImage *img = [self imageFromSampleBuffer:buffer];
if (img != nil) {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
img = [self imageOfSize:CGSizeMake(320, 480) fromImage:img];
[images addObject:img];
[pool release];
}

CMSampleBufferInvalidate(buffer);
CFRelease(buffer);
buffer = nil;

}
NSLog(@"value: %d", val++);
}

[images removeLastObject];
NSLog(@"img count: %d", [images count]);
NSLog(@"imgs: %@",images);

[theAVAsset release];
[mAssetReader release];
[mAssetReaderOutput release];
NSLog(@"count: %d", [images count]);
}

当 while 循环执行时,它会打印我在递增整数 val 时放置的日志。在此期间,有时 GDB 中会显示一条消息“Received Memory warning”。

非常感谢...

最佳答案

听起来您需要考虑将 while 循环的每次迭代包装在自动释放池中 https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html

关于iPhone - 收到内存警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11643877/

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