Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

下载图片时,内存突然升高导致app被杀 #686

Closed
GorCat opened this issue May 23, 2017 · 9 comments
Closed

下载图片时,内存突然升高导致app被杀 #686

GorCat opened this issue May 23, 2017 · 9 comments

Comments

@GorCat
Copy link

GorCat commented May 23, 2017

喵神,祝安。

我有一个 tableView,每个 cell 有 0 ~ 9 张的图片,在 cell 将要展示的时候加载图片,但在频繁的滑动 tableView 的时候,CPU 和 Memory 会增高,最后被杀掉。

我使用 Kingfisher 3.2.4 , maxMemoryCost 设置为 1。

Allocation 收集在 iPhone6s 10.3.2 上运行的结果如下图显示,每次在杀掉前都走了 VM:ImageIO_jpeg_Data 和 VM:ImageIOGetCachedBlock,

f59ea914-decc-42c4-a399-67ccc6415bcc

是我使用 Kingfisher 不当而造成的问题么?

@GorCat GorCat changed the title 系统被杀,通过 Allocation 发现每次被杀之前都走了 ImageIO_jpeg_Data 下载图片时,内存突然升高导致系统被杀 May 23, 2017
@GorCat
Copy link
Author

GorCat commented May 23, 2017

这个问题可以 100% 复现

@GorCat
Copy link
Author

GorCat commented May 23, 2017

加载图片的代码如下:

`
/// 加载图片
public func loadImage() {

        for imageObject in picuresArray {

            let imageUrl = TSURLPath.imageURLPath(storageIdentity: Int(imageObject.storageIdentity), compressionRatio: ratio)!

            button.kf.setImage(with: imageUrl, for: .normal)

       }

}

`

取消图片加载代码如下:

`
/// 取消加载图片

public func cancelLoadImage() {

    for imageObject in picuresArray {

        let index = picuresArray.index(of: imageObject)!

        let button = viewWithTag(basicTagForImageButton + index) as! TSPreviewButton

        button.kf.cancelImageDownloadTask()

    }

}

`

@onevcat
Copy link
Owner

onevcat commented May 23, 2017

There is little thing I could do unless I can reproduce the problem. How could I reproduce your issue? Anything like a sample project or some steps to crash the app would be a great help.

A common reason according to your description might be that you are using the full version of images as thumbnails (say the image view is only 50x50 but you are loading a 1000x1000 image into it).

@GorCat GorCat changed the title 下载图片时,内存突然升高导致系统被杀 下载图片时,内存突然升高导致app被杀 May 23, 2017
@GorCat
Copy link
Author

GorCat commented May 24, 2017

图片都是根据实际展示大小对分辨率进行了压缩的,那我先整理出一个 Demo,然后麻烦喵神有空的时候帮忙看一下了,整理好后我吧 Demo 发到你的邮箱哈 ~

@GorCat
Copy link
Author

GorCat commented May 24, 2017

已发送 Demo。

@GorCat
Copy link
Author

GorCat commented May 25, 2017

问题已解决,是我的问题

@ddffsg
Copy link

ddffsg commented Aug 7, 2018

@GorCat 能说一下具体原因吗,我也遇到了类似的问题

@ddffsg
Copy link

ddffsg commented Aug 7, 2018

如果我这边需要批量加载缩略图,但服务器那边只给了我完整图,我该怎么处理降低内存啊

@xiaoyao20084321
Copy link

如果我这边需要批量加载之上,但服务器那边只给了我完整图,我该怎么处理降低内存啊

同问, 你怎么解决的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants