Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 02-13-2010, 03:49 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Question UIScrollView Consuming Tons of Memory

Greetings,

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?

Thanks, Joel

Code:
-(void)loadScrollViewPageSandwich:(NSInteger)pageIndex
	{
	NSLog(@"ViewController Count Inbound: %i", [self.cardViewControllerArray count]);
	for (FDMCardViewController* thisViewController in self.cardViewControllerArray)
		{
		[thisViewController.view removeFromSuperview];
		NSLog(@"Releasing view controller: %@", thisViewController);
		[thisViewController release];
		}
	[self.cardViewControllerArray removeAllObjects];
	
	for (id thisSubview in [self.scrollView subviews])
		{
		NSLog(@"Removing subview: %@", thisSubview);
		[thisSubview removeFromSuperview];
		}
	
	for (int n = pageIndex - 1; n < pageIndex + 2; n++)
		{
		int localIndex = n;
		if (localIndex < 0) localIndex = 0;
		if (localIndex >= self.pageControl.numberOfPages) localIndex = self.pageControl.numberOfPages - 1;
		FDMCardViewController* cardViewController = [[FDMCardViewController alloc] initWithPageNumber:localIndex];
		cardViewController.delegate = self;
		cardViewController.pageObject = [[self enabledCardsArray] objectAtIndex:localIndex];

		CGRect frame = scrollView.frame;
		frame.origin.x = frame.size.width * localIndex;
		frame.origin.y = 0;
		cardViewController.view.frame = frame;
		[scrollView addSubview:cardViewController.view];
		
		NSLog(@"Adding this view controller: %@", cardViewController);
		[self.cardViewControllerArray addObject:cardViewController];
		}
	NSLog(@"ViewController Count Outbound: %i", [self.cardViewControllerArray count]);
	}
Quote:
2010-02-12 18:49:42.158 FDM_v2.0.35x[648:20b] ViewController Count Inbound: 0
2010-02-12 18:49:42.158 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x156bde0; frame = (1280 0; 320 372); autoresize = RM+BM; layer = <CALayer: 0x156bb10>>
2010-02-12 18:49:42.159 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x156bd90; frame = (1600 0; 320 372); autoresize = RM+BM; layer = <CALayer: 0x156bbb0>>
2010-02-12 18:49:42.159 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x156b8c0; frame = (1920 0; 320 372); autoresize = RM+BM; layer = <CALayer: 0x156b6f0>>
2010-02-12 18:49:42.160 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x157af20>
2010-02-12 18:49:42.162 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x155ce30>
2010-02-12 18:49:42.168 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x1532540>
2010-02-12 18:49:42.169 FDM_v2.0.35x[648:20b] ViewController Count Outbound: 0
2010-02-12 18:49:42.949 FDM_v2.0.35x[648:20b] ViewController Count Inbound: 0
2010-02-12 18:49:42.950 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x157cf00; frame = (1600 0; 320 460); autoresize = RM+BM; layer = <CALayer: 0x157cc30>>
2010-02-12 18:49:42.951 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x157cbb0; frame = (1920 0; 320 460); autoresize = RM+BM; layer = <CALayer: 0x157d0d0>>
2010-02-12 18:49:42.952 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x157ca20; frame = (2240 0; 320 460); autoresize = RM+BM; layer = <CALayer: 0x157c740>>
2010-02-12 18:49:42.953 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x1579020>
2010-02-12 18:49:42.954 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x157bff0>
2010-02-12 18:49:42.962 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x1534c80>
2010-02-12 18:49:42.962 FDM_v2.0.35x[648:20b] ViewController Count Outbound: 0
MobileJoel is offline   Reply With Quote
Old 02-13-2010, 09:11 PM   #2 (permalink)
Registered Member
 
tawpie's Avatar
 
Join Date: Jul 2008
Posts: 347
Default

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)
tawpie is offline   Reply With Quote
Old 02-15-2010, 05:19 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 4
Unhappy No Joy on releasing cardViewController

Quote:
Originally Posted by tawpie View Post
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
MobileJoel is offline   Reply With Quote
Old 02-21-2010, 08:41 PM   #4 (permalink)
Registered Member
 
tawpie's Avatar
 
Join Date: Jul 2008
Posts: 347
Default

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)
tawpie is offline   Reply With Quote
Reply

Bookmarks

Tags
memory, pages, scroll, uiscrollview, view

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 268
18 members and 250 guests
14DEV, ADY, ArtieFufkin10, Dani77, HemiMG, IphoneSdk, jakerocheleau, JasonR, jimbo, MACralik, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:56 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0