My closure retains itself. It causes capturing all other objects inside. I can pass such objects using weak reference, but it doesn't solve the problem of retain cycle. What's the right way to do recursion with closures without retain cycles?
class Foo {
  var s = "Bar"
  deinit {
    print("deinit") // Won't be executed!
  }
}
class TestVC: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    let foo = Foo() // Weak works, but not the right solution.
    var closure: () -> Void = { return }
    closure = {
      print(foo.s)
      if true {
        return
      } else {
        closure()
      }
    }
  }
}
 
     
     
    