I was hoping someone could help me with a memory issue on the iPhone.
I have a scrollview that is part of a nav controller.
Whenever I first push the nav controller and scroll through the scrollview (adding images as I go), memory is allocated in huge chunks (say 1mb each).
If I rotate the display a couple of times, the memory is freed, and everything is fine: The scrollview works correctly and the memory returns to where it should be (around 1mb, looking at the Net alloc in Instruments).
How can I keep the memory from going wild, or free it up during use of the scrollview, just as the device rotation does?
Here is the code snippet that is called to load the scrollview page:
- (void)loadPage:(int)page isCurrent:(BOOL)isCurrent {
if (page < 0) return;
if (page >= totalRows) return;
picViewController *controller = [[picViewController alloc] init];
if ((NSNull *)[viewControllers objectAtIndex:page] == [NSNull null]) {
NSString *fullPath = [self fullPath];
if([fileManager fileExistsAtPath:fullPath]) {
currentImage=[UIImage imageWithContentsOfFile:fullPath];
[controller setImg:currentImage];
[viewControllers replaceObjectAtIndex:page withObject:controller];
}
else {
AsyncImageView* asyncImage = [[AsyncImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
asyncImage.tag = 8;
[asyncImage loadImageFromName:imageName withURL:url];
[controller.view addSubview:asyncImage];
[asyncImage release];
[viewControllers replaceObjectAtIndex:page withObject:controller];
}
if (nil == controller.view.superview) {
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
}
[controller release];
}
}