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

Using startLoadingBeforeViewAppear() with a nil URL causes a memory leak and high cpu #2035

Closed
3 tasks done
BobbyRohweder opened this issue Feb 22, 2023 · 0 comments · Fixed by #2036
Closed
3 tasks done

Comments

@BobbyRohweder
Copy link

BobbyRohweder commented Feb 22, 2023

Check List

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

Issue Description

What

A memory leak and 100% cpu occurs from a loop caused by using startLoadingBeforeViewAppear() on a KFImage with a nil url.

Each time the view body is called, the "binder.start" is called and fails the initial context.source guard, which then triggers objectWillChange, and then restarts the loop of attempting to re-render the body. This continues to happen since "loadingOrSucceeded" will always return false for nil URLs.

Reproduce

Example code:

let optionalImageURL: URL? = nil
KFImage(optionalImageURL)
    .startLoadingBeforeViewAppear()

Call stack:

#0 in closure #1 in KFImage.ImageBinder.start<τ_0_0>(context:) at SwiftUI/ImageBinder.swift:61
#1 in closure #2 in CallbackQueue.execute(_:) at Utility/CallbackQueue.swift:54
#2 in OS_dispatch_queue.safeAsync(_:) at Utility/CallbackQueue.swift:78
#3 in CallbackQueue.execute(_:) at Utility/CallbackQueue.swift:54
#4 in KFImage.ImageBinder.start<τ_0_0>(context:) at SwiftUI/ImageBinder.swift:55
#5 in closure #1 in KFImageRenderer.body.getter at SwiftUI/KFImageRenderer.swift:41

Other Comment

Kingfisher version: 7.5.0
iOS version: 16.X

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

Successfully merging a pull request may close this issue.

1 participant