RAD Studio
ContentsIndex
PreviousUpNext
Memory Management of Interface Objects

One of the concepts behind the design of interfaces is ensuring the lifetime management of the objects that implement them. The _AddRef and _Release methods of IInterface provide a way to implement this lifetime management. _AddRef and _Release track the lifetime of an object by incrementing the reference count on the object when an interface reference is passed to a client, and will destroy the object when that reference count is zero. 

If you are creating COM objects for distributed applications (in the Windows environment only), then you should strictly adhere to the reference counting rules. However, if you are using interfaces only internally in your application, then you have a choice that depends upon the nature of your object and how you decide to use it.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!