Reputation: 53
Well, memory management makes me crazy!
Here's my problem:
I have a plist with n references to images. What I'm just trying to do is grab each child and load it to an UIImageView wich is added to a UIScrollView with paging enabled.
My problems:
I read about CATiledLayer, and saw the PhotoScroller sample, but I want avoid using CATiledLayer because it creates a fadein while showing the pieces of the image, and in my project that effect don't fit.
I'm just want hear your opinion, how do you usually solve this kind of tasks?
I will leave here a piece of my code:
UIImage * image;
UIImageView * imageview;
for (int i = 0; i < [data count]; i++)
{
image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] bundlePath],
[[data objectAtIndex:i] objectForKey:@"content"]]];
[content addObject:image];
imageview = [[UIImageView alloc] initWithImage: [content objectAtIndex:i] ];
[imageview setTag:i+10];
imageview.frame = CGRectMake(1024 * i, 0, 1024, 768);
[scroll addSubview: imageview];
[imageview release];
[image release];
}
[scroll setContentSize:CGSizeMake(1024*[data count], 768)];
This code make the app receive a memory warning when I try to load 60 images for instance.
I think you get the idea, right?
Any suggestions?
Thanks for your help in advance!
Upvotes: 1
Views: 1198
Reputation: 8163
If you want to avoid memory problems, you should not load them all at once, only when they are needed. To accomplish this, you could just follow the example provided by apple, here.
Basically, what you do is load only three images: the one that is showing right now and the ones that are placed to the right and to the left. Then, when you scroll, let's say to the right, you remove the one that was previously on the left side and place a new image at the right end.
Upvotes: 3