gpt4 book ai didi

ios - 带有GCD的图像加载接收内存警告

转载 作者:行者123 更新时间:2023-12-01 16:51:16 24 4
gpt4 key购买 nike

我正在使用AssetsLibrary开发照片库应用程序以加载设备照片。当在另一个VC中呈现随机图像时,我注意到以下几点:我的完整分辨率图像在imageView上加载大约要花费1或2秒的时间(比本地的photosApp长得多),并且我也从日志“收到加载一些图像后出现“内存警告”。如果我将表示形式设置为fullScreenImage,则警告会停止,但我不希望这样做。要在 View 上获得平滑的性能和高质量的图像,必须更改什么?

这是代码,希望您能告诉我是什么问题:

这是我要在屏幕上显示我的图像的VC

- (void)viewDidLoad
{
[super viewDidLoad];

NSLog(@"%@",assetsController);

detailImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:detailImageView];
detailImageView.image = smallImage; //small image is my asset thumbnail and is passed as an argument in my init function

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

ALAsset *asset = [assetsController.albumPics objectAtIndex:assetsController.index];
ALAssetRepresentation *representation = [asset defaultRepresentation];

bigImage = [[UIImage imageWithCGImage:[representation fullResolutionImage]]retain];

dispatch_async(dispatch_get_main_queue(), ^{

detailImageView.image = bigImage;

});
[pool release];
});
}

更新1
    {
UIImageView *detailImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:detailImageView];
detailImageView.image = smallImage;


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

ALAsset *asset = [assetsController.albumPics objectAtIndex:assetsController.index];
ALAssetRepresentation *representation = [asset defaultRepresentation];

UIImage *bigImage = [UIImage imageWithCGImage:[representation fullResolutionImage]];


dispatch_async(dispatch_get_main_queue(), ^{

detailImageView.image = bigImage;

});
[pool release];

});
}

最佳答案

bigImage是实例变量吗?除了这里以外,是否在其他地方使用过?如果未在其他任何地方使用它,则它应该是局部变量,并且您不应该保留它。如果保留的是实例变量,则需要释放前一个值,然后再为其分配新值。

同样的讨论适用于detailImageView

关于ios - 带有GCD的图像加载接收内存警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15572028/

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