user3648985
user3648985

Reputation:

Setting the high resolution image to UIimageView create memory issue

I have app that have two screen. i am sending UIImage object from first screen to second and set this image to UIImageview in second screen.

But when i tried to set image in UIImageview my memory spike goes to 116 up. My image resolution is above 2040*2040

Here is my code

.h file

@property (weak, nonatomic) IBOutlet UIImageView *aimageView;
@property (weak, nonatomic) UIImage *sourceImage;

.m file

- (void)viewDidLoad
{
    [super viewDidLoad];

    aimageView.image = sourceImage;
    [aimageView setContentMode:UIViewContentModeScaleAspectFit];
    sourceImage = nil;
}

Upvotes: 0

Views: 393

Answers (1)

Liam
Liam

Reputation: 12678

When an image is uncompressed in memory it can take up a lot of memory.

If you are developing for iPhone, where the max screen resolution is 640x1136 then why do you need to load a 2040x2040 image at once?

If you need to efficiently handle large images in your app, it might be worth looking at using a CATiledLayer. This would allow you to split large images down into smaller image tiles and then only load the tiles the user wants to see on the screen.

Apple have a sample project that you can find here.

Upvotes: 1

Related Questions