There is retain cycle between the Signal
(a Signal
is created when you start the producer, hence the name: SignalProducer
) and the observer, when you use methods of the family start...
.
You have three ways to break this cycle:
- You dispose of the
SignalProducer
(if you notice, you get aDisposable
, when you use astart...
). You should avoid doing this, as it goes against RAC best practises - You have a way to manipulate the
SignalProducer
. In your case you do have, by sending complete to theObserver
. - You use methods like
take
,takeWhile
,until
, which will terminate theSignalProducer
. This is the prefered way.
Regarding the dispatch. Try this in your viewDidLoad
:
timer(3, scheduler: QueueScheduler(name: "hello.scheduler")).map { _ in "hello" }.startWithNext { print($0) }
You will notice that although your viewDidLoad
is long gone, it will still print "hello".