3.2.3.1 The Normal Case
In the normal case, the TP Framework completely controls the
lifetime of a servant. The basic model is that, when a request for
an inactive object arrives, the TP Framework obtains a servant and
then activates it (by calling its activate_object
method). At deactivation time, the TP Framework calls the
servant’s deactivate_object
method and then
disposes of the servant.
The phase “the TP Framework obtains a servant” means
that when the TP Framework needs a servant to be created, it calls
a user-written Server method, either
Server::create_servant
or
ServerBase::create_servant_with_id
. At that time, the
application code must return a pointer to the requested servant.
The application almost always does this by using the C++
“new” statement to create a new instance of a servant.
The phrase “disposes of the servant” means that the TP
Framework removes the reference to the servant, which actually
deletes it.
The application must be aware that this current behavior of
always creating and removing a servant may change in future
versions of this product. The application should not depend on the
current behavior, but should write servant code that allows reuse
of a servant. Specifically, the servant code must work even if the
servant has not been freshly created (by the C++ “new”
statement). The TP Framework reserves the right not to remove a
servant after it has been deactivated and then to reactivate it.
This means that the servant must completely initialize itself at
the time of the callback on the servant’s
activate_object
method, not at the time of servant
creation (not in the constructor).
Parent topic: Servant Lifetime