Memory leak in Apples 'Scrolling' sample code
- by John
Hi All,
I'm using code based on Apple's "Scrolling" sample code - here's where I have a problem:
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= jNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"page%d.png", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView2 = [[UIImageView alloc] initWithImage:image];
The UIImageView causes a leak - it doesn't seem to be releasing (though I do state [imageView2 release]; after adding the imageView as a subView to scrollView2 I have say 15 chapters of a book each held in a nav bar, each containing a scroll view with one chapters worth of these image views (each image is a page).
When I get to around the second last chapter the app crashes due to the memory leaks... really annoying! I think it might be because imageView's been alloc'd twice (in alloc and in addSubView) but i'm not sure.... tried releasing twice but it didn't seem to help. any pointers?
Thanks in advance ^.^