开发者

How many images can I load into a NSMutableArray to show in ImageView?

开发者 https://www.devze.com 2023-02-20 19:50 出处:网络
I need to load 150 JPEG images that are 100Kb each, but I get a memory warnings after loading 110 JPEGs at 60Kb each.

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.

0

精彩评论

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