Memory leak in Apples 'Scrolling' sample code
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-04-23T10:18:06Z
Indexed on
2010/04/23
10:23 UTC
Read the original article
Hit count: 312
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 ^.^
© Stack Overflow or respective owner