Akka.Actor.ActorCell.FinishTerminate C# (CSharp) Method

FinishTerminate() private method

private FinishTerminate ( ) : void
return void
        private void FinishTerminate()
        {
            // The following order is crucial for things to work properly. Only change this if you're very confident and lucky.
            // 
            // Please note that if a parent is also a watcher then ChildTerminated and Terminated must be processed in this
            // specific order.
            var a = _actor;
            try
            {
                if (a != null)
                {
                    a.AroundPostStop();

                    // run actor pre-incarnation plugin pipeline
                    var pipeline = _systemImpl.ActorPipelineResolver.ResolvePipeline(a.GetType());
                    pipeline.BeforeActorIncarnated(a, this);
                }
            }
            catch (Exception x)
            {
                HandleNonFatalOrInterruptedException(
                    () => Publish(new Error(x, _self.Path.ToString(), ActorType, x.Message)));
            }
            finally
            {
                try
                //TODO: Akka Jvm: this is done in a call to dispatcher.detach()
                {

                    //TODO: Akka Jvm: this is done in a call to MessageDispatcher.detach()
                    {
                        var mailbox = Mailbox;
                        var deadLetterMailbox = System.Mailboxes.DeadLetterMailbox;
                        SwapMailbox(deadLetterMailbox);
                        mailbox.BecomeClosed();
                        mailbox.CleanUp();
                        Dispatcher.Detach(this);
                    }
                }
                finally
                {
                    try { Parent.SendSystemMessage(new DeathWatchNotification(_self, existenceConfirmed: true, addressTerminated: false)); }
                    finally
                    {
                        try { TellWatchersWeDied(); }
                        finally
                        {
                            try { UnwatchWatchedActors(a); }
                            finally
                            {
                                if (System.Settings.DebugLifecycle)
                                    Publish(new Debug(_self.Path.ToString(), ActorType, "Stopped"));

                                ClearActor(a);
                                ClearActorCell();
                                
                                _actor = null;
                                
                            }
                        }
                    }
                }
            }
        }