Hi all,
Having recently taken up app development, i've reached the stage where my app does what I want it to do, and I'm trying to fix any bugs that exist. Unfortunately, I've got a memory leak...
I have a nav bar in a tab app, each row of the nav bar's table view contains a link to a new view, which all contain a row of images within a scrollview. I'm pretty sure this is where my problem is:
^^ i'm pretty sure the problem is that the image(x).png is not being released, but I can't figure out where I can release it - should i add it to the .h file so i can dealloc it at the end?
Having recently taken up app development, i've reached the stage where my app does what I want it to do, and I'm trying to fix any bugs that exist. Unfortunately, I've got a memory leak...
I have a nav bar in a tab app, each row of the nav bar's table view contains a link to a new view, which all contain a row of images within a scrollview. I'm pretty sure this is where my problem is:
Code:
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor blackColor];
// 1. setup the scrollview for multiple images and add it to the view controller
//
// note: the following can be done in Interface Builder, but we show this in code for clarity
// [scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView1.scrollEnabled = YES;
scrollView1.pagingEnabled = YES;
scrollView1.bounces = YES;
scrollView1.directionalLockEnabled = YES;
scrollView1.maximumZoomScale = 1.0;
scrollView1.minimumZoomScale = 1.0;
scrollView1.multipleTouchEnabled = YES;
scrollView1.delegate = self;
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
Code:
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i; // tag our images for later use when we place them in serial fashion
[scrollView1 addSubview:imageView];
[imageView release];
}
[self layoutScrollImages];
}