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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-13-2010, 02:49 PM   #1 (permalink)
MobileJoel
Registered Member
 
Join Date: Nov 2009
Posts: 4
MobileJoel is on a distinguished road
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
 

» Advertisements
» Online Users: 756
16 members and 740 guests
7twenty7, armmzz, drckmchaels, erdinc27, Fahad.bhutta, falco1973, iAppDeveloper, iOS.Lover, MarkC, matador1978, momolgtm, m_rozzi, Sophie100, thewitt, tim0504, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,474
Threads: 94,040
Posts: 402,625
Top Poster: BrianSlick (7,978)
Welcome to our newest member, m_rozzi
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:05 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.