Article ID: 311273 - Last Review: January 5, 2006 - Revision: 4.2

The ObjectAllocatedByClass callback does not return the exact number of objects allocated

This article was previously published under Q311273
Expand all | Collapse all

SYMPTOMS

The ObjectAllocatedByClass callback provides only an approximation of the number of objects allocated since the most recent garbage collection (GC). That number may be larger than, smaller than, or equal to the number of objects actually allocated.

CAUSE

ObjectAllocatedByClass gets the number of objects allocated since the previous GC by walking the Gen0 heap. However, objects (for example, pinning pointers) can be demoted and thus stay in the Gen0 heap after the previous GC. As the result, objects may be recounted by objectAllocatedByClass.

RESOLUTION

To ensure that the profiler gets accurate results, you should use the ObjectAllocated callback to count how many objects are allocated. The profiler will get ObjectAllocated notification only when the COR_PRF_MONITOR_OBJECT_ALLOCATED and COR_PRF_ENABLE_OBJECT_ALLOCATED event masks are set in the profiler. Note that because of the large number of notifications fired from a typical program, this is very costly in profiling overhead.

STATUS

This behavior is by design.

MORE INFORMATION

For additional information on CLR profiling, click the article number below to view the article in the Microsoft Knowledge Base:
309551  (http://support.microsoft.com/kb/309551/EN-US/ ) INFO: CLR Profiling Services Problems

APPLIES TO
  • Microsoft .NET Framework 1.0
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
Keywords: 
kbtshoot kbperformancetool kbprb KB311273
 

Article Translations