The following memory–management policies are used for all client interfaces described in this chapter:
When a function returns a non-const pointer to an object, the client “owns” the object. The client can alter the object and is responsible for freeing the space allocated to it when the object is no longer required.
When a function returns a const pointer to an object, the service “owns” the object. The client must neither modify the object in any way, nor free the space allocated to it. If the client needs to control a copy, it must make one for itself.
When a function takes a non-const parameter that is passed by reference, the service “borrows” the object during the function's execution. It can modify the object during this period, but it does not retain any reference to the object beyond this period.
When a function takes a const parameter that is passed by reference, the service reads but does not modify the object. The service does not keep any reference to the object beyond the period of the function's execution.