0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

iOS アプリにおける画像の大量表示に起因するメモリ枯渇への対応

Posted at

問題

開発中の iOS アプリにおいて、写真を大量に表示した際にメモリ枯渇によりアプリが突然終了してしまう問題に直面した。

Simulator 上で問題を再現させた際には、以下のエラーメッセージが出力された。

Domain: IDEDebugSessionErrorDomain
Code: 4
Failure Reason: Message from debugger: Terminated due to memory issue
User Info: {
    IDERunOperationFailingWorker = DBGLLDBLauncher;
}

具体的には、以下のように SwiftUI の LazyVGrid を使って画像を大量に表示させた際にこの問題は発生した。

LazyVGrid(columns: self.columns, alignment: .center, spacing: 0.0) {
    ForEach(entries, id:\.self) { entry in
        EntryView(entry: entry)
    }
}

解決方法

表示させる画像の解像度を下げることで、この問題を解消することができた。
具体的には、以下のページで紹介されている downsampling の処理を利用した。
https://swiftsenpai.com/development/reduce-uiimage-memory-footprint/

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?