I've got a UIScrollView that can contain 50-100+ pages, each of which have a FDMCardViewController (my own class which basically consists of a NIB with a UIImageView that loads a full-screen .png file per page). I am aware that only the controller/view for the current page plus those to the L and R really need to be in memory/the UIScrollView, which is what I'm trying to achieve with the code below. Even thought it's not the most efficient page loading implementation (as it reloads all 3 pages each time), I think I am being thorough in purging all of the previous controllers/views each time. Nevertheless, memory usage steadily climbs and the app grinds to a halt as you progressively scroll through the pages. Additionally, the console log shows that the array I'm using to contain the in-use controllers isn't really functioning properly (always has a count of zero).
Can anyone see any glaring errors and/or suggest any sample code/projects that successfully implement a UIScrollView with large numbers of pages?
I'd start with releasing the cardViewController after you add it to the array. The array should retain the controller--check it with retainCount.
__________________
"Hardware will break. Software comes broken" Unknown Calc-12E <-- ditch your old calculator. CPR•Choking <-- Review your training, just in case. (Free) All of Nature NW <-- scrolls in x and y, with pinch zoom AND scrollable text to boot. It can be done ('taint easy tho)
I'd start with releasing the cardViewController after you add it to the array. The array should retain the controller--check it with retainCount.
Yes, a good thought, and when I had tried that I found that manually releasing the cardViewController at the end of the method results in the loss of handling of touch events (which is the only other thing FDMCardViewController does aside from load the image). Using an autorelease when cardViewController is instantiated results in the same condition and neither one seems to help reduce memory consumption.
I am still baffled at why the array size always remains the same (zero) even when I add/remove objects that clearly exist according to the NSLogs. For a test I even tried to add an arbitrary string (e.g., @"Test String") to the array and it still doesn't grow in size. Very odd.
Lastly, I have looked at Apple's PageControl sample code and I see that even with the very small pages that they're adding to the UIScrollView, the memory usage steadily creeps up there too (albeit at such a slow rate that the effects aren't detrimental). Is there something inherently problematic in UIScrollView?
Still hoping for some insight or a reference to some known good code.
Thanks again, Joel
of course you did make self.cardViewControllerArray a mutable array yes?
The only reason I can think of that you aren't getting the correct "count" is that somehow the array or its pointer is mashed and pointing into the ozone somewhere.
__________________
"Hardware will break. Software comes broken" Unknown Calc-12E <-- ditch your old calculator. CPR•Choking <-- Review your training, just in case. (Free) All of Nature NW <-- scrolls in x and y, with pinch zoom AND scrollable text to boot. It can be done ('taint easy tho)