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.
精彩评论