TITLE: naming convention for memory ownership [ Erich Gamma is one of the Design Patterns authors. This article came from a the design patterns discussion group. -adc ] PROBLEM: Andrew James I am implementing a Builder using the GOF book as a reference text. The Builder in the GOF book contains a pointer to its product as a private member. When the Builder client gets the product, the Builder simply returns the address of its private product. Doesn't this have some potential memory leaks? RESPONSE: erich_gamma@acm.org (Erich Gamma), 30 Jan 96 The pattern description is not explicit about who owns the product (the Builder destructor isn't shown). The typical convention is to pass ownership of the product to the client. It is then the client's responsibility to delete it. As you point out whenever you pass an object's ownership to another object you can introduce memory managment problems. To make such a transfer more explicit it is helpful to follow the naming conventions as described in "Taligent's Guide to Designing Programs." Operations that pass the ownership of an object and therefore the responsibility to delete it to the caller start with Orphan. Orphan sets the corresponding variable to 0. Operations that take over ownership from the caller start with Adopt. If the receiver already owns such an object the old object is deleted.