See how to trace references to COM objects:
|Tracing References to Interfaced Objects|
The Reference Count profiler tracks the number of references to interface objects. The following sections provide an overview of the Reference Count profiler:
About COM Reference Counting
COM does not automatically remove objects from memory when they are no longer used. A COM object's lifetime depends on the number of references to it, that is, the object lives as long as there is at least one reference to it. To implement reference counting, every COM object supports the IUnknown interface or its descendants. The interface declares the
Release methods that increment or decrement the object reference counter.
The general idea of reference counting is as follows:
Each COM object maintains a special variable that stores the current number of references to the object.
When a new client acquires access to the object’s interface, the reference counter is increased by the
When the client has finished using the COM object, the counter is decreased by the
If the reference counter equals zero, the object is no longer required and can be released.
Some high-level programming languages, like Delphi and Visual Basic, provide automatic reference counting. In these languages, a new reference is added automatically when a new object is created. And when the object goes beyond its visibility scope, references to it are automatically removed. Thus, COM objects are typically used without explicit calls to the
However, there can still be situations when you need to call these methods manually. In other programming languages, for example, in C++, the programmer should care about reference counting all by himself. When these methods are called manually, each
AddRef should have a matching
Release call. If the number of
AddRef calls does not match the number of
Release calls, the interface object can never be freed or can be destroyed prematurely. This will cause memory leaks and access violations in the application.
To avoid such issues, use the Reference Count profiler to track the number of references to interface objects within your application.
The Reference Count Profiler analyzes the use of objects that implement the
IUnknown interface or its descendants. The main goal of the profiler is locate unreleased or prematurely released interface objects. It logs calls to the
Release methods, traces their call stack and reports how many references were used for each object, in total and as a peak count for the run.
To control which modules are included into the stack collected by the Reference Count profiler, AQTime provides you with the Collect Stack Information Pane. For more information on specifying modules, classes and methods that are included into the stack, see Specifying Modules to Be Included Into the Call Stack.
The Reference Count profiler operates during the entire run of the application. It takes no account of triggers and actions and disables the Enable/Disable Profiling button.
The Reference Count profiler automatically generates results when the profiled application is terminated or the Get Results button is clicked (see Getting Results During Profiling). Analyzing the profiling results you can find objects that remain in memory when the results are generated or inspect references that are created and released during the application run.
The profiling results are displayed in the Report panel and are organized into the Classes Data and Objects categories. The Classes Data category provides a general overview of which classes produce interface objects, while the Objects category provides a detailed report on each interface object that existed at time when results were generated. See the topics of the Reference Count Profiler Results section for detailed information.