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



The information in this article applies to:

  • Microsoft .NET Framework 1.0
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)

This article was previously published under Q311273

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 INFO: CLR Profiling Services Problems


Modification Type:MajorLast Reviewed:1/5/2006
Keywords:kbtshoot kbPerformanceTool kbprb KB311273 kbAudDeveloper