iMessage应用程序 - 将GIF显示为UICollectionViewCell时内存泄漏?

问题描述 投票:1回答:1

Memory warning

大家好,我的记忆有问题。我尝试使用Kingfisher将GIF图像显示为UICollectionViewCell。每次我回到之前的ViewController并回到当前的ViewController时,内存正在成长(加倍)。我正在使用RxSwift和一些相关的库。

这是调用giphy api源,并绑定到集合视图:

provider = RxMoyaProvider<Giphy>()
    giphyTrackerModel = GiphyTrackerModel(provider: provider, gifUrl: latestGiphyName)
    giphyTrackerModel
        .trackGiphy()
        .bindTo(collectionView.rx.items(cellIdentifier: "SearchCell", cellType: SearchCell.self)) {
            (index, giphyDataModel, cell) in
            cell.delegate = self
            cell.giphy = giphyDataModel
        }
        .addDisposableTo(disposeBag)

这是我的SearchCell.swift:

import UIKit
import Kingfisher    
class SearchCell: UICollectionViewCell {

    @IBOutlet weak var gifImageView: UIImageView!

    override func awakeFromNib() {
        super.awakeFromNib()

        gifImageView.layer.cornerRadius = 4
        gifImageView.layer.masksToBounds = true
        self.backgroundColor = Color.lightGray
        self.layer.cornerRadius = 4
    }

    weak var giphy: GiphyDataModel! { 
        didSet {
            if let gifUrl = giphy.images?.downsized?.url { 
                 let url = gifUrl.characters.count != 0 ? URL(string: gifUrl) : URL(string: "")
                 gifImageView.kf.setImage(with: url)
             }
        }
    }
}
ios swift memory-leaks gif imessage
1个回答
0
投票

尝试使用MSStickerView而不是UIImageView。它应该减少一点内存使用量。它也可能是缓存文件的问题。你应该检查一下。

© www.soinside.com 2019 - 2024. All rights reserved.