-->

How can I get reference count for a managed object

2019-07-12 05:06发布

问题:

.NET profilers can show reference count to managed objects. How do they count them?

回答1:

They use unmanaged APIs which provide access to the profiler.

ICorProfilerCallback and ICorProfilerCallback2 are the main ones. These are the the interfaces that .NET profilers use. There are some more references like this.

You can use the methods for class loads (ClassLoadFinished()) and unloads (ClassUnloadFinished()) to track this information.