Using the default Scheduler in Akka, do I need to manually cancel events when the target actor stops?
akka, cancellation, scheduling
Solution
The variants of `Scheduler.schedule` which take an `ActorRef` will not watch that actor (which would have a rather high overhead relative to what a timer task is), hence you should always clean up the recurring timer from the actor’s `postStop` hook.
In the local case we check `target.isTerminated`, but that method always returns `false` for actor references which are not of the bog-standard local kind, hence you can rely on this feature only in specific cases and your code would then stop working correctly when you scale out your application. Another consideration is that the aforementioned check runs when trying to send the message, which can be a “soft leak” (i.e. deferred cleanup) in case of long schedules (where depending on the use-case 100ms can already be long).
Problem
When using the methods on the default Akka system scheduler (`context().system().scheduler().schedule()` from inside an actor), and one of the overloads accepting a destination actor, do I need to explicitly cancel using the returned Cancellable to free up resources when the destination actor stops? I imagine the scheduler may be `watch()`ing the destination actor and automatically perform the cleanup but cannot find it explicitly state anywhere in the documentation.