Search code examples
reactive-cocoa

Lifetime of RACSignal


Normally an object is alive as long as there is a strong reference to the object.

But what if I don't have a strong reference to the signal and I subscribe, will the subscription terminate?

RACSignal *signal = ...;
[signal subscribeNext:^{
   // Will this ever be called if I don't keep a strong reference to `signal`?
}];

Solution

  • When you subscribe to a signal, that callback is essentially added to a global register that also keeps a strong reference to the signal. To shorten its lifetime you'll need to use a takeUntil:.