在iPhone上令人困惑的内存分配错误

在iPhone上令人困惑的内存分配错误

本文介绍了在iPhone上令人困惑的内存分配错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用iPhone应用程序,该应用程序提供有关图像和文本的信息.在每个文本中都有一个图像,可以单击并缩放该图像,并显示一个UIImageView

Hello I'm working on an iPhone application which provides information with images and texts. In every text there is one image, which can be clicked and zoomed, shown with a UIImageView

    NSString* imgName = [imgPath substringToIndex:[imgPath rangeOfString:@".jpg"].location];
UIImage* img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imgName ofType:@"jpg"]];
[imgView setImage:img];

当我逐个打开图像以查看图像时,应用崩溃了(在设备上调试).控制台出现错误:

as I go through the images by opening them one by one the app crashes(debug on device). with some error in console:

:减压错误my_app_name(1226,0x3e088868)malloc: * mmap(size = 32768)失败(错误代码= 12)* 错误:无法分配区域

: Decompression errormy_app_name(1226,0x3e088868) malloc: * mmap(size=32768) failed (error code=12)* error: can't allocate region

然后:

CoreAnimation:无法分配2228352字节.

CoreAnimation: failed to allocate 2228352 bytes.

我的代码没有泄漏,如果我不打开图像,也不会收到错误消息.有人知道这个问题可能在哪里吗?

I don't have leak in code and if I do not open the images I don't get the error. so does anyone have a clue where this problem could be?

推荐答案

似乎您使用的内存过多?

Seems you are using too much memory?

您打开多少张图片?从连接的仪器开始,观察内存占用情况.

How many images do you open? Start with instruments attached and watch the memory footprint.

请记住,图像在加载时比在磁盘上压缩要占用更多的内存.

Keep in mind that images take much more memory when loaded than compressed on disk.

这篇关于在iPhone上令人困惑的内存分配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 12:22