Microsoft KB Archive/311273

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

Article ID: 311273

Article Last Modified on 1/5/2006

-

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

-



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

Keywords: kbtshoot kbperformancetool kbprb KB311273

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.