Webtoon Viewer를 만들 때 나와 했던 고민이 똑같았다.
UIImageView를 사용해서 image를 보여주자니 메모리가 webview에서 보여주는것보다 더 나왔다.
질문에 대한 대답으로
Reducing Memory Footprint When Using UIImage
위 링크를 걸어줬다.
링크처럼 해당 방법처럼 시도를 했다. 메모리는 줄었다.
하지만 저장하고 있는 이미지들을
images = nil
처럼 지워줬다고 했는데 계속 쌓였다.
(부연 설명을 하자면 나는 웹툰 뷰어를 만들고 있는 중이었다. 웹툰의 소스는 이미지들이고, 이것을 세로로 스크롤 가능하게 붙여서 사용할 예정)
흠 그래서 봤다
Memory use is related to the dimensions of the image, not the file size.
Session 416, WWDC 2018
According to the video, in order to show an image on screen, iOS will first need to decode and decompress the image. Typically, 1 pixel of a decoded image will take up 4 bytes of memory — 1 byte for red, 1 byte for green, 1 byte for blue, and 1 byte for the alpha component.
Takes our sample image with dimension 3648px × 5472px as an example:
(3648 * 5472) * 4 bytes ≈ 80MB
이미지 크기가 3648px × 5472px 라면 1px당 r, g, b, alpha가 각 1byte씩 총 4 byte가 사용된다하면 대략 80MB가 사용된다는 말이다!
(우와 엄청 크다.)
웹툰은 스크롤이 엄청 길다.
이 엄청은 어느정도냐면..
scroll content height가 10만이다!!(이것은 iPad mini다. iPad mini의 pixel size는 2266*1488 이다. 화면이 총 44개 이어 붙여져 있다는 뜻이다.(height = 2266 기준))