#はじめに
現在開発しているiPhoneアプリに関する質問になります。
#問題
カスタムで作成したCollectionViewCellにUIimageViewをのせ、SDWebImageを使用して、そのCollectionViewCellにのせたimageViewにネット上の画像を表示させております。
実装は以下です。
SomeViewController.swift private var dataSource = [SomeObject]() func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCollectionViewCell", for: indexPath) as! CustomCollectionViewCell cell.configure(data: dataSource[indexPath.item]) return cell }
CustomCollectionViewCell.swift @IBOutlet weak var imageView: UIImageView! func configure(data: SomeObject) { imageView.sd_setImage(with: URL(string: data.imageURL)!, placeholderImage: nil, options: SDWebImageOptions.retryFailed, completed: nil) } override func prepareForReuse() { super.prepareForReuse() imageView.sd_cancelCurrentImageLoad() }
上記のCustomCollectionViewCellを80件ほど表示しており、以下のような表示です
※上記の実装内容は省略している部分があります。
何度もスクロールをおこなうと、下記のメモリーが多い時で450MB~600MBまで跳ね上がり、
クラッシュして落ちてしまいます。この時
Message from debugger: Terminated due to memory issue
のメッセージがコンソールで確認されました
CustomCollectionViewCellが再生成されるタイミングで、imageView.sd_cancelCurrentImageLoad()
を行なっておりますが、あまり意味をなしてなさそうです。何かわかる方おりましたら、教えていただけますと幸いです。よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/27 12:47