-
Notifications
You must be signed in to change notification settings - Fork 150
Open
Description
Like the title says there is a retain cycle in the various bind(to:input:)
functions. The following test fails:
it("does not create a retain cycle") {
var subject: UIBarButtonItem? = UIBarButtonItem(barButtonSystemItem: .save, target: nil, action: nil)
let action = Action<String, String>(workFactory: { _ in
return .empty()
})
subject?.rx.bind(to: action, input: "Hi there!")
weak var subjectWeakReference = subject
subject = nil
expect(subjectWeakReference).to(beNil()) // fails!
}
The retain cycle is due to passing base
to inputTransform
in map
. This can be fixed by changing the various bind
methods to the following:
self.tap // or controlEvent
.withUnretained(self.base) // no longer retaining base!
.map(\.0)
.map(inputTransform)
.bind(to: action.inputs)
.disposed(by: self.base.actionDisposeBag)
With the change above all tests plus the one I added to check for a retain cycle pass. I'd be happy to write up a pull request to make these changes if you agree they need to be made.
P.s. Thanks for the great framework!
nakp
Metadata
Metadata
Assignees
Labels
No labels