tags:

views:

91

answers:

1

My UIButton has it's background image set like this:

[myImageButton setBackgroundImage:[UIImage imageNamed:myImageName] forState:UIControlStateNormal];

myImageButton is a retained property of the class, and is setup with IB. No where else is it accessed in the app.

myImageName is simply an NSString with a filename like @"myImage_number_1.png"

I am loading large images, 1024 x 1024 in size. When the view is shown, it changes the image with the above statement, then available memory decreases.

After I see the view about 7-9 different times, the app crashes with a memory warning.

I thought the method would free up the loaded image.

The view itself is only instantiated and allocated one time, so it's not in the retain/release cycle if the view controller.

Is there something about this setBackgroundImage I don't know that causes it to not release memory?

+1  A: 

Ah, found it. Every time imageNamed is used to load an image, it caches the image in memory. I switched to imageWithContentsOfFile - it doesn't cache images.

just_another_coder