objective-c memory friendly way for background image

231 views Asked by At

i have an ipad app (>30 views / pages) each view has a unique background.

the problem: whats the best way to set the background (memory friendly)

is there a better way than adding: uiimageview "backgroundView" as a subview?

version1:

[[UIImage alloc] initWithData:imageData];

which seems to be problematic with the retina switch

version2:

self.layer.contents = (id)image.CGImage;

version 3:

UIImage* image = [UIImage imageWithContentsOfFile:fileLocation];

version 2 seems to work fine. maybe someone tell me whats the best approach, and why ;)

thank you Alex

2

There are 2 answers

0
Dream.In.Code On

CGImage is problematic with retina ... version3. is best for memory friendly !

3
guitarflow On

In version 2, you generate a new image object which you have to release manually if you don't use ARC. Version 3 uses an autoreleased object.

Both versions are equal in memory-friendlyness. I'd prefer version 3 because you don't have to do anything yourself to free the memory.

You could also use [UIImage imageNamed:@"image-name.png"], which also generates an autoreleased object.

If you want it as memory-friendly as possible, you should consider using PVR images, as those are natively supported by the graphics hardware.

Best,

Flo