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 05-18-2010, 06:57 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: London, UK
Posts: 12
eagerterrier is on a distinguished road
Default Memory usage goes through the roof when adding UIImageViews

I have a project where I am asynchronously loading images from my site. All was working fine, until I started doing a gallery view for the app, when I noticed that the memory usage went through the roof when I add a bunch of small images.

I was trying storing images on file and also in memory with no change.

Typically, the app bumbles along for c.2Mb until I hit the gallery page, when it shoots up to 5Mb and then up to 10Mb on the gallery detail page.

The weird thing is that when I add the images on the 5Mb-10Mb jump I am adding just 3 images of c.130Kb

Also, when I comment out the line

Code:
[self addSubview:async_imageView];
Memory stays low. So, it is not the getting the image and storing it in a finite cache that is causing the image, but rather displaying it in the view: Everything is released where it should be and I can't see where I can alter the code to avoid memory issues.

Anyone have any suggestions as to what I might try next?


Many thanks.
eagerterrier is offline   Reply With Quote
Old 05-18-2010, 09:56 AM   #2 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,070
scotopia is on a distinguished road
Default

What are the pixel dimensions of the images you are displaying?
scotopia is offline   Reply With Quote
Old 05-18-2010, 10:03 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: London, UK
Posts: 12
eagerterrier is on a distinguished road
Default

Quote:
Originally Posted by scotopia View Post
What are the pixel dimensions of the images you are displaying?
570 wide, flexi height - not massive by any means...
eagerterrier is offline   Reply With Quote
Old 05-18-2010, 11:02 AM   #4 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,070
scotopia is on a distinguished road
Default

Quote:
Originally Posted by eagerterrier View Post
570 wide, flexi height - not massive by any means...
Hmm...that might account for what you are seeing. In memory this will round up to a 1024x1024 texture, which is 2MB of RAM for a single image of this size right there.
scotopia is offline   Reply With Quote
Old 05-18-2010, 11:26 AM   #5 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: London, UK
Posts: 12
eagerterrier is on a distinguished road
Default

Dammit. I thought that only applied when you had either side of your view (imageview/scrollview etc) larger that 1024. The largest one I have that I can see is 575x879. All the rest are smaller.

I'm not keen on using CATiledLayer. Do you know what the best procedure is for dealing with images of this size? I guess just respond well to didReceiveMemoryWarning?

I'm thinking of removing any images not on the screen from the superview and maybe removing images from the cache also (although this seems like overkill in this situation as they are only taking up 140K each)

I have a 400 wide image option. I've tried using this instead and it's now down to a jump up to 9Mb.


thanks, scotopia
eagerterrier is offline   Reply With Quote
Old 05-18-2010, 11:49 AM   #6 (permalink)
Registered Member
 
scotopia's Avatar
 
Join Date: Oct 2008
Posts: 2,070
scotopia is on a distinguished road
Default

No problem. Yeah, in memory any images round up to the smallest power of 2 square texture containing your dimensions; so unfortunately a 513x1 becomes a 1024x1024 in memory. Anything you can do to reduce the number of images displayed simultaneously or shrink things down to the next threshold (512x512 in this case) would help.
scotopia is offline   Reply With Quote
Old 05-18-2010, 11:55 AM   #7 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: London, UK
Posts: 12
eagerterrier is on a distinguished road
Default

Quote:
Originally Posted by scotopia View Post
No problem. Yeah, in memory any images round up to the smallest power of 2 square texture containing your dimensions; so unfortunately a 513x1 becomes a 1024x1024 in memory. Anything you can do to reduce the number of images displayed simultaneously or shrink things down to the next threshold (512x512 in this case) would help.
Right, now you've said this, that makes sense.

In my gallery detail viewcontroller, I am laying blank pages out in a row horizontally using pagination. So when I have no images in there, everything is fine.

I then load up the image the user has requested and one each side. When they scroll one way or the other, I am loading up another image in the direction they are going.

So, it's not the individual images themselves, but the fact that I am loading three at once, which makes the scrollview container, *way* bigger than 1024x1024.

I guess I load up just one image at a time and remove the others from superview on scroll. Not ideal by any means, but at least the app won't crash.

Thanks, scotopia, you've been a great help
eagerterrier is offline   Reply With Quote
Reply

Bookmarks

Tags
asynch images, images, memory management, uiimageview

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: 306
9 members and 297 guests
Abidullah, ajay123123, Fstuff, guusleijsten, HemiMG, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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