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

标签 ios swift memory-leaks gif imessage

Memory warning

大家好,我的内存有问题。我尝试使用 Kingfisher将 GIF 图像显示为 UICollectionViewCell。每次我回到以前的 ViewController 并回到当前的 ViewController 时,内存都会奇怪地增长(加倍)。我将 RxSwift 与一些相关库一起使用。

这是调用 giphy api 源码,并绑定(bind)到 Collection View :

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)
             }
        }
    }
}

最佳答案

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

关于ios - iMessage 应用程序 - 将 GIF 显示为 UICollectionViewCell 时内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41098380/

相关文章:

c - CreateList 函数(链表)中的内存泄漏

iphone - 每次触摸UIButton时将值增加1

swift - UITextField 在输入之前显示 "Optional("")"

android - 使用截击监听器时 Activity 泄漏

ios - 项目未从共享扩展记录到 CoreData

ios - 如何使用代码连接数据源和委托(delegate) - iOS Swift

objective-c - 核心数据内存管理

ios - 获取元素的当前约束

ios - 我的 iOS 框架中的异常显示私有(private)代码?

ios - 无论如何我可以在 iOS swift 中添加一个文本字段,它需要多个值?