我有一个简单的UIViewViewController
应用,带有UILabel
个插座。我有一个MutableProperty<String?>
我绑定到label.reactive.text
这会导致57个内存泄漏。绑定两个可变属性是否总是泄漏内存,如果是这样,为什么?
class ViewController: UIViewController {
@IBOutlet weak var testLabel: UILabel!
let testText: MutableProperty<String?> = MutableProperty("")
override func viewDidLoad() {
super.viewDidLoad()
let signal = textSignal()
testText <~ signal
testLabel.reactive.text <~ testText
DispatchQueue.main.asyncAfter(deadline: .now() + 6) {
UIApplication.shared.keyWindow?.rootViewController = UIViewController()
}
}
func textSignal() -> SignalProducer<String, NoError> {
return SignalProducer<String, NoError>{ (sink: Observer, disposable: Disposable) in
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
sink.send(value: "Hello world")
print("sink Hello world")
}
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
sink.send(value: "Wabbu Labbu dub dub")
print("sink Wabbu Labbu dub dub")
}
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
sink.sendCompleted()
print("sink compeleted")
}
}
}
}