Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从文件加载UIImage时会占用大量内存_Ios_Objective C_Uiimage_Memory Warning - Fatal编程技术网

Ios 从文件加载UIImage时会占用大量内存

Ios 从文件加载UIImage时会占用大量内存,ios,objective-c,uiimage,memory-warning,Ios,Objective C,Uiimage,Memory Warning,在我的iPad应用程序中,我使用ALAsset和以下代码从照片流加载了100幅图像: ALAsset *asset = [assets objectAtIndex:[sender tag]]; ALAssetRepresentation *representation = [asset defaultRepresentation]; UIImage *image = [[UIImage alloc] initWithCGImage:[representation fullScreen

在我的iPad应用程序中,我使用ALAsset和以下代码从照片流加载了100幅图像:

  ALAsset *asset = [assets objectAtIndex:[sender tag]];
  ALAssetRepresentation *representation = [asset defaultRepresentation];
  UIImage *image = [[UIImage alloc] initWithCGImage:[representation fullScreenImage]
                                                     scale:1.0f
                                               orientation:0];
一切都很完美。但是,当我将其作为JPEG文件缓存到文件系统中,然后使用
UIImage*image=[UIImage imageWithContentsOfFile:fullPath]
再次加载它们时,应用程序会因内存警告而崩溃,我可以在探查器中看到它确实使用了大量RAM。 为什么会这样?

有一件事

从gallery加载图像时,为什么不存储
assetur
,而不是
UIImage
;这将占用更少的空间并提高速度


当您需要显示时,使用缩略图表示,也许?

好的,这是我的错。我发现了这个问题,结果发现我在任何情况下都有记忆问题
ALAsset
imageWithContentsOfFile
的工作原理完全相同


现在我将尝试找到减小每个图像大小的方法。

使用@autorelease在循环中释放内存。类似于下面的代码:-(void)useALoadOfNumbers{for(int j=0;j<10000;++j){@autoreleasepool{for(int I=0;I<10000;++I){NSNumber*number=[NSNumber numberwhithint:(I+j)];NSLog(@“number=%p”,number);}}}我正在尝试这个。我曾尝试在不同的地方使用它,但没有成功。更多信息:嗯,问题是我没有实际的循环。我知道@autoreleasepool,现在正试图以不同的方式使用它。问题是,我必须能够打开这些图片,即使它们已从照片中删除Stream@flybirdx然后,您应该创建一个数据库并从资产库复制所有图像。@pawan我该怎么做?@flybirdx您可以使用sqlite或核心数据来存储图像。@pawan您认为存储二进制数据会更好吗?