开发者

(iphone) loading png to UIImage takes up more memory than png binary size?

开发者 https://www.devze.com 2023-02-02 10:50 出处:网络
I\'m loading 100s 4k-8k png files(768*768 resolution), total less than 1mg. Although I do convert them to UIImage and resize/combine images occasionaly,

I'm loading 100s 4k-8k png files(768*768 resolution), total less than 1mg.

Although I do convert them to UIImage and resize/combine images occasionaly,

I was surprised to see ipad device die 开发者_开发知识库because of memory warning due to the image loadings.

Is converting to UIImage takes up much more memory than actual byte size of the file?

Thank you.


That's because png's are decompressed into memory, taking more memory. And each decompressed image will take up to 768*768*4 = 2.25 MByte of memory.


You might want to consider how you load images if they aren't all for simultaneous display. There are lots of threads about this here and elsewhere, such as this thread.

UIImage imageNamed will cache the image (and sometimes Apple's caching is slightly buggy, not releasing properly) whilst UIImage imageWithData won't, so once no longer displayed, the memory will be released. There are advantages and disadvantages to both depending on your circumstances, so try to get a good understanding of the differences.

0

精彩评论

暂无评论...
验证码 换一张
取 消