UIImages

Apprentice
Posts: 17
Joined: 2010.01
Post: #1
I need to know how to release my images! What I have done is, declared an (IBOutlet UIImageView *main) In the .h file. Then I have four buttons in my .m file and when you press each button it is setting the UIImageView "main" to a deferent image with this code:
[main setImage:[UIImage imageNamed:@"My Image.jpg"]];
I need to know how to release "main" after every button press, because it is allocating memory for every image when the buttons are pressed.
Quote this message in a reply
Member
Posts: 27
Joined: 2008.12
Post: #2
You don't need to release the image because you didn't alloc/init it; but imageNamed *does* keep a cached copy around in case you need the image again. That's probably where the extra memory is coming from.

The method imageWithContentsOfFile doesn't keep that cached copy, so it should use less memory for you.

Code:
main.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"My Image.jpg" ofType:nil]];

Also be sure to release "main" in your dealloc method.

-- Available Now: Dead Panic, a casual zombie shooter!
-- Development Blog: How to make a game under $1k
-- Twitter: xsmasher
Quote this message in a reply
Apprentice
Posts: 17
Joined: 2010.01
Post: #3
Thank you, I will try it and see how it works!
Quote this message in a reply
Apprentice
Posts: 17
Joined: 2010.01
Post: #4
I need help releasing, I have 4 view controllers and when I go from the 1st view to the second view, the "dealloc" method for the second view is being called, and not my first view "dealloc" method! Why is the dealloc method for the view that I am leaving not getting invoked, instead the view that I am going to! What am I doing wrong? Please help.
P.S the first view dealloc method is never being invoked!
Quote this message in a reply
Member
Posts: 27
Joined: 2008.12
Post: #5
Post some code. How are you displaying the second view? Are you releasing it without retaining it somewhere?

-- Available Now: Dead Panic, a casual zombie shooter!
-- Development Blog: How to make a game under $1k
-- Twitter: xsmasher
Quote this message in a reply
Post Reply