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

Trikot.viewmodels DefaultImageViewModelHandler is leaking subscription to imageFlow #14

Open
marcantoinefortier opened this issue Jan 21, 2022 · 0 comments
Labels
bug Something isn't working viewmodels Issue related to Trikot.viewmodels subproject

Comments

@marcantoinefortier
Copy link
Contributor

Assigning an ImageViewModel to a UIImageView does not cancel the subscription to the viewModel's imageFlow when the UIView is deallocated.

class MyView: UIView {

    private let myImageView = UIImageView()

    var myViewModel: MyViewModel {
        didSet {
             myImageView.imageViewModel = myViewModel.imageViewModel
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)

        addSubview(myImageView)   
    }

    deinit {
        // We need to manually set the image's viewModel to nil, otherwise the subscription to the imageFlow is never cancelled
        myViewModel.imageViewModel = nil
    }
}
@marcantoinefortier marcantoinefortier added bug Something isn't working viewmodels Issue related to Trikot.viewmodels subproject labels Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working viewmodels Issue related to Trikot.viewmodels subproject
Projects
None yet
Development

No branches or pull requests

1 participant