ReactiveX / RxSwift

Reactive Programming in Swift
MIT License
24.34k stars 4.17k forks source link

DeallocObservable deinit #2313

Closed Wormprocess closed 3 years ago

Wormprocess commented 3 years ago

:warning: If you don't have something to report in the following format, it will probably be easier and faster to ask in the slack channel first. :warning:

class Header: UIView {
    var disposeBag = DisposeBag()
//    var button : UIButton?
    override init(frame: CGRect) {
        super.init(frame: frame)

        let btn : UIButton = UIButton.init(frame: .init(x: 0, y: 0, width: 200, height: 100))
        btn.backgroundColor = .cyan
        self.addSubview(btn)

        btn.rx.tap.subscribe { (e) in
            print("点击了\(e)")
        }.disposed(by: disposeBag)

//        self.button = btn
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

//    deinit {
//        print("释放了\(self.subviews)--")
//    }
}

这个view 被释放的时候 tap.subscribe 会响应一次,  打开deinit 方法 就不会响应了, 用了 self.button = btn 也不会响应了 是为什么?

:warning: Please take you time to fill in the fields below. If we aren't provided with this basic information about your issue we probably won't be able to help you and there won't be much we can do except to close the issue :( :warning:

If you still want to report issue, please delete above statements before submitting an issue.

Short description of the issue:

description here

Expected outcome:

what you expect to happen goes here

What actually happens:

what actually happens goes here

Self contained code example that reproduces the issue:

  code goes here

// If we can't get a self contained code example that reproduces the issue, there is a big chance we won't be able
// to help you because there is not much we can do.
//
// `Self contained code example` means:
//
// * that we should be able to just run the provided code without changing it.
// * that it will reproduce the issue upon running

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

version or commit here

Platform/Environment

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

Xcode version:

  Xcode version goes here

:warning: Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. :warning:

Installation method:

I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)

Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)

freak4pc commented 3 years ago

Hey, I'm sorry but this issue doesn't include any explanation of what is the issue itself. Please clean up the issue template and explain what the problem is.

Also, I unfortunately can't read Chinese, so if you can try your best to translate to English that would be very helpful. Thank you!

Xiangao2018 commented 3 years ago

hey @Wormprocess , i. try your code and can not reproduce the problem,maybe you should check your code again

The isssue should be closed