views:

36

answers:

3

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?

+1  A: 

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.

Eiko
Hi Eiko thank you for the reply. it crashes when I open about 30 images, but I always release the old one when I open a new one. All images are under 100kb (on Mac).
boreas
the instrument shows an overall allocated memory 15Mb, which was mainly taken by my speech output stuffs. and I saw some Malloc 1+Mb in the category, called by CG Graphics, I don't understand how this could come.
boreas
An image needs about pixels_hor * pixels_ver * 4 bytes when loaded, and the error message indicates it wants around 2 MB. Maybe check if they are really freed. Instruments gives a good graph on memory usage.
Eiko
A: 

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

Pete
A: 

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.

boreas