Problem dealloc'ing memory used by UIImageViews with fairly large image in an UIScrollView

前端 未结 7 1898
遥遥无期
遥遥无期 2020-12-03 03:58

I have a large UIScrollView into which I\'m placing 3-4 rather large (320x1500 pixels or so) UIImageView image tiles. I\'m adding these UIImageViews to the scroll view insi

7条回答
  •  旧巷少年郎
    2020-12-03 04:25

    Completing the answer of Bdebeez.

    One nice idea is to override the imageNamed: calling the imageWithContentsOfFile:.

    Here is the idea of the code:

    @implementation UIImage(imageNamed_Hack)
    
    + (UIImage *)imageNamed:(NSString *)name {
    
        return [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] bundlePath], name ] ];
    }
    
    @end
    

    Note: With this override you will not have any cache loading UIImages, if you need this, you will have to implement your own cache.

提交回复
热议问题