Why does my UIImage take up so much memory?

后端 未结 3 1428
夕颜
夕颜 2021-01-02 13:25

I have a UIImage that I\'m loading into one of my app\'s views. It is a 10.7 MB image, but when it loads in the app, the app\'s resource usage suddenly jumps by 50 MB. Why

3条回答
  •  一生所求
    2021-01-02 14:12

    You can do one thing. if you can afford 50 MB for this image. If this image with 10 mb size is that much critical to your application then. you can release it just after its use to keep memory usage in control. As you are using ARC there is no option for release but you can do this

    @autoreleasepool {
    UIImage *image = [UIImage imageNamed:@"background.jpg"];
    self.backgroundImageView = [[UIImageView alloc] initWithImage:image];
    [self.view addSubview:self.backgroundImageView];        
    }
    

    using autoreleasepool it will be sure that after this autoreleasepool{} block memory for fat image will be deallocated. making your device RAM happy again.

    Hope it helps !

提交回复
热议问题