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 08-29-2011, 10:49 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 1
jimmytan is on a distinguished road
Default How to save iPad memory if I use the same image many times?

hi,

Bear with me if this question has been asked before.

I have an app that has over 270 buttons, and for simplicity of explanation, I assign pretty much the same button image as the background for these 270 buttons in IB. The size of the button image is only 16KB.

The Activity Monitor in Instruments shows the iPad memory usage of my app to close to 80MB, and I would imagine the 270 buttons would have contributed a significant portion to the memory load. I have checked to ensure there are no memory leaks.

My understanding is that currently, the same button image is loaded 270 times into memory (correct me if I'm wrong).

My question is - is there a way to load the button image only once in memory, and reuse it 270 times for each of the 270 buttons? ie, all 270 buttons share the same memory location. I do not do any image manipulation, and the image is used as a background.

Thanks for any inputs.
jimmytan is offline   Reply With Quote
Old 08-30-2011, 02:32 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

this should do the trick...
Code:
UIImage *myImage = [UIImage imageNamed:@"yourButton.png"];
__________________
dany_dev is offline   Reply With Quote
Old 08-31-2011, 12:03 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Location: USA
Posts: 18
Ridgewood is on a distinguished road
Default

dany_dev is on the right track, if a bit terse :-) I work primarily in C++ and OpenGL where I use texture IDs for this. In Objective C, you should be able to re-use your static image data pointer as many times as you want w/o using additional memory, just don't release/free it and you should be able to use the pointer you requested over and over again.
__________________
Apps:
Exian - Brick out in space

www | Twitter | Facebook
Ridgewood is offline   Reply With Quote
Old 08-31-2011, 03:19 AM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by Ridgewood View Post
dany_dev is on the right track, if a bit terse :-) I work primarily in C++ and OpenGL where I use texture IDs for this. In Objective C, you should be able to re-use your static image data pointer as many times as you want w/o using additional memory, just don't release/free it and you should be able to use the pointer you requested over and over again.
really is more than that.....I said to use imageNamed because
UIImage Class Reference
Quote:
This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.
so you can use it to create multiple images using 1 image in cache.
__________________
dany_dev is offline   Reply With Quote
Old 08-31-2011, 12:39 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2011
Location: USA
Posts: 18
Ridgewood is on a distinguished road
Default

Cool, I didn't know imageNamed had that functionality. Depending on the situation, retaining the image pointer might be better performance-wise.
__________________
Apps:
Exian - Brick out in space

www | Twitter | Facebook
Ridgewood is offline   Reply With Quote
Reply

Bookmarks

Tags
memory, uiimage

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: 396
5 members and 391 guests
JackReidy, jeroenkeij, Sami Gh, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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