Skip to content

Trikot.viewmodels DefaultImageViewModelHandler is leaking subscription to imageFlow #14

Description

@marcantoinefortier

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
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingviewmodelsIssue related to Trikot.viewmodels subproject

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions