2

If I have the following code

func handle(showEmptyView: Driver<Bool>) {
    showEmptyView
        .drive(onNext: setEmptyViewShown)
        .disposed(by: disposeBag)
}

func setEmptyViewShown(_ show: Bool) {
    tableView.isHidden = !show
    emptyView.isHidden = show
}

Is this a retain cycle when I call setEmptyViewShown because I don't use weak or unowned self?

Dávid Pásztor
  • 45,571
  • 9
  • 73
  • 100
Mr.P
  • 1,291
  • 14
  • 33
  • Why don't you check with the Profiler, which will tell you with 100% certainty if you have a retain cycle? – Dávid Pásztor Jun 04 '20 at 09:08
  • Do you know you can check whether retain cycles _actually exist_ using Xcode? See [this](https://stackoverflow.com/questions/41660486/knowing-where-retain-cycles-are-and-removing-them/41661291#41661291). – Sweeper Jun 04 '20 at 09:09

1 Answers1

1

Yes there is a retain cycle because setEmptyViewShown(_:) is a method which takes self as an implicit first argument.

Better would be something like:

disposeBag.insert(
    showEmptyView.bind(to: emptyView.rx.isHidden),
    showEmptyView.map { !$0 }.bind(to: tableView.rx.isHidden)
)
Daniel T.
  • 29,518
  • 5
  • 47
  • 65