Kingfisher icon indicating copy to clipboard operation
Kingfisher copied to clipboard

真机测试 使用真机同时加载 7 张以上特殊的 45K的 gif 图会 crash,使用 demo 能复现,但是加载其他的 2M 左右的却不会,怀疑发现了某个特殊 bug。

Open YunyueLin opened this issue 1 year ago • 3 comments

发现一个问题,使用真机同时加载 7 张以上特殊的 45K的 gif 图会 crash,使用 demo 能复现,url 在下面。

What

有点奇怪45k 的图片为什么会这样,因为线上其他 2M及以上的图片不会出现这个问题。 且尝试了 AnimatedImageView 也有概率出现内存过高导致 crash。 使用最新版本和 6.3.1 都测试了,都会 crash。

Reproduce

图片 Url: https://cdn.kkyuehui.com/img_10306_187744906.gif?imageView2%2F2%2Fw%2F1200%2Fh%2F1200%2Fq%2F75%7Cimageslim

demo 修改之后的代码如下: class GIFHeavyViewController: UIViewController { let stackView = UIStackView() let imageView_1 = AnimatedImageView() let imageView_2 = AnimatedImageView() let imageView_3 = AnimatedImageView() let imageView_4 = AnimatedImageView()

override func viewDidLoad() {
    super.viewDidLoad()

    stackView.translatesAutoresizingMaskIntoConstraints = false
    
    view.addSubview(stackView)
    
    if #available(iOS 11.0, *) {
        NSLayoutConstraint.activate([
            stackView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
            stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
            stackView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
            stackView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
        ])
    } else {
        NSLayoutConstraint.activate([
            stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            stackView.topAnchor.constraint(equalTo: view.topAnchor),
            stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
            stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
        ])
    }
    
    stackView.axis = .vertical
    stackView.distribution = .fillEqually
    
    stackView.addArrangedSubview(imageView_1)
    stackView.addArrangedSubview(imageView_2)
    stackView.addArrangedSubview(imageView_3)
    stackView.addArrangedSubview(imageView_4)
    
    imageView_1.contentMode = .scaleAspectFit
    imageView_2.contentMode = .scaleAspectFit
    imageView_3.contentMode = .scaleAspectFit
    imageView_4.contentMode = .scaleAspectFit
    
    let url = URL(string: "https://cdn.kkyuehui.com/img_10306_187744906.gif?imageView2%2F2%2Fw%2F1200%2Fh%2F1200%2Fq%2F75%7Cimageslim")
    //https://raw.githubusercontent.com/onevcat/Kingfisher-TestImages/master/DemoAppImage/GIF/GifHeavy.gif

    imageView_1.kf.setImage(with: url)
    imageView_2.kf.setImage(with: url)
    imageView_3.kf.setImage(with: url)
    imageView_4.kf.setImage(with: url)
    //这里循环次数 6 是crash临界点,测试真机是iPhone13。
    for i in 0...6 {
        let imgView = UIImageView()
        imgView.contentMode = .scaleAspectFit
        imgView.kf.setImage(with: url)
        stackView.addArrangedSubview(imgView)
    }
}

}

Other Comment

感谢。

YunyueLin avatar Mar 08 '23 08:03 YunyueLin

最新版本是 7.6.2

YunyueLin avatar Mar 08 '23 08:03 YunyueLin

连接真机后Crash也不会进堆栈信息,而是Xcode 直接弹 Alert 报错:

The app “XXX” on XXX quit unexpectedly. Message from debugger: Terminated due to memory issue

YunyueLin avatar Mar 08 '23 08:03 YunyueLin

连接真机后Crash也不会进堆栈信息,而是Xcode 直接弹 Alert 报错:

The app “XXX” on XXX quit unexpectedly. Message from debugger: Terminated due to memory issue

这是内存溢出了,Kingfisher加载gif确实会比较吃内存

feixue299 avatar Apr 03 '23 05:04 feixue299