Kingfisher icon indicating copy to clipboard operation
Kingfisher copied to clipboard

ImageView retained by kingfisher when it should be dealloc

Open bing-feng-v587 opened this issue 1 year ago • 4 comments

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

Issue Description

What

when vc poped, imageview should dealloc, but it not happend when loading image use kingfisher. and it real deinit after load remote image finish.

kingfier retain imageview by self.base

Reproduce

[The steps to reproduce this issue. What is the url you were trying to load, where did you put your code, etc.]

Other Comment

[Add anything else here]

bing-feng-v587 avatar Oct 23 '24 09:10 bing-feng-v587

As the KingfisherWrapper itself is a struct (which contains the actual image view as a reference), it would be quite difficult to prevent the holding in the closure. If the extended lifetime is not desired, you can try to call cancelDownloadTask on the imageView.kf to terminate the processing:

class MyViewController: UIViewController {
    deinit {
        imageView.kf.cancelDownloadTask()
    }
}

onevcat avatar Oct 23 '24 13:10 onevcat

wow, it used in many places. This approach doesn't seem to work. Will there be no optimization for this area in the future?

bing-feng-v587 avatar Oct 24 '24 01:10 bing-feng-v587

@bing-feng-v587 When you write, ‘This approach doesn’t seem to work,’ do you mean that the proposed solution isn’t fixing the problem, or is it not acceptable for your project because there are many parts of your codebase that would need to be adapted?

Adobels avatar Nov 11 '24 20:11 Adobels

yes, there are many parts in my code that need to be adapted

bing-feng-v587 avatar Nov 12 '24 01:11 bing-feng-v587