开发者

confusing memory allocation error on iPhone

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:

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

and then:

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?


oh I think I finally fixed it. and yes my images are relative large, about 700*600 in size.

the problem seems to be in [imgView setImage:img]; the img is although released but somehow still in memory, I don't know. One line code [imgView setImage:nil]; before releasing imgView in dealloc fixes the problem.

Thank you for the helps.


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.


Try wrapping-up your allocations/releases in a local auto release pool.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜