def prepare_destruction(self):
        """Prepares the model for destruction

        Un-registers itself as observer from the state machine and the root state
        """
        try:
            self.relieve_model(self.state_machine_model)
            assert self.__buffered_root_state_model is self.state_machine_model.root_state
            self.relieve_model(self.__buffered_root_state_model)
            self.state_machine_model = None
            self.__buffered_root_state_model = None
            self.modifications.prepare_destruction()
        except KeyError:  # Might happen if the observer was already unregistered
            pass
        if self.active_action:
            try:
                self.active_action.prepare_destruction()
            except Exception as e:
                logger.exception("The modification history has had left over an active-action and "
                                 "could not destroy it {0}.".format(e))
            self.active_action = None