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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-13-2010, 11:32 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 16
IckyThump is on a distinguished road
Default Loading images to UIScrollview crashes

Hello All.

I have a Navigationcontroller pushing a UIViewController with a scrollview inside. Within the scrollview I download a certain number of images around 20 (sometimes more) each sized around 150 KB.

All these images are added to the scrollview so that their origin is x +imageSize and the following is sorted right to the one before.

All in all I think its a lot of data (3-4 MB).
On an I pod Touch this sometimes crashes, the IPhone can handle it once, if it has to load the data again (some other images) , it crashes too.

I guess its a memory issue but within my code, I download the image, save it to a file on the phone as NSData, read it again from file and add it to a UIImageview which I release. So I have freed the memory I allocated, nevertheless it still crashes.

Can anyone help me out? Since Im new to this, I dont know the best way to handle the Images in a scrollview.

Besides I create the controller at start from nib, which means I dont have to release it, since I dont use alloc - right?

Code:

In my rootviewcontrller I do:

Code:
-(void) showImages {

	

	[[self naviController] pushViewController:imagesViewController animated:YES];
	[imagesViewController viewWillAppear:YES];
	 
	
}


- (void) loadOldImageData {

	
	for (int i = 0; i < 40 ; i++) {
		
		
		NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
		NSString *documentsDirectory = [paths objectAtIndex:0];
		NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"img%d.jpg", i]];
		
		
		
		
		
		NSData *myImg = [NSData dataWithContentsOfFile:filePath];
		UIImage *im = [UIImage imageWithData:myImg];
		
		
		if([im isKindOfClass:[UIImage class]]) {
			NSLog(@"IM EXISTS");
			
			UIImageView *imgView = [[UIImageView alloc] initWithImage:im];
			
			
			CGRect frame = CGRectMake(i*320, 0, 320, 416);
			imgView.frame = frame;
			
			[myScrollView addSubview:imgView];
			[imgView release];
		
			
			
			//NSLog(@"Adding img %d", i);
			numberImages = i;
			NSLog(@"setting numberofimages to %d", numberImages);
			//NSLog(@"scroll subviews %d", [myScrollView.subviews count]);

		}
		
	}
	
	
	myScrollView.contentSize = CGSizeMake(320 * (numberImages + 1), 416);
	
	
}
IckyThump is offline   Reply With Quote
Reply

Bookmarks

Tags
crash, iphone, memory, uiscrollview

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: 337
9 members and 328 guests
Absentia, Domele, fiftysixty, givensur, heshiming, linkmx, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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