How many images can I load into a NSMutableArray to show in ImageView?
I need to load 150 JPEG images that are 100Kb each, but I get a memory warnings after loading 110 JPEGs at 60Kb each.
My array is:
imagesSet = [[NSMutableArray alloc] init];
and images are loaded like this:
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@%d", IMAGE_PREFIX, i] ofType:IMAGE_FORMAT];
NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
[imagesSet addObject:[UIImage imageWithData:ima开发者_StackOverflow中文版geData]];
and
show:imageView.image = [imagesSet objectAtIndex:[number intValue]];
Is there not enough memory? Or am I doing something wrong?
You are exceeding the memory of a mobile device by far. Remember that a JPEG image will get decoded after being loaded. To calculate the actual amount of memory needed for a single image, you may run this formula: (width * 4) * height when using an UIImageView.
精彩评论