RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TComObject.RefCount Property

Indicates the number of references to the COM object that are currently in use.

Pascal
property RefCount: Integer;
C++
__property int RefCount;

RefCount is used to determine when the object can be destroyed. RefCount is the number of references to interfaces implemented by the COM object. When RefCount is zero, the object can be is destroyed. 

RefCount is automatically incremented when references to interfaces implemented by the COM object are created, and is automatically decremented when those references are destroyed. RefCount is usually incremented by the IUnknown AddRef method and decremented by the IUnknown method, Release

RefCount can be artificially incremented when a new object is created which may be passed as a function parameter. In this case, RefCount should not be zero, and should be incremented prior to the function call and decremented when the function returns.

Note: In Delphi code, the CreateFromFactory method artificially increment and decrements RefCount.
Note: In C++ code, if you pass a class factory to the constructor as the first parameter, the constructor artificially increments and decrements RefCount.
 

 

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