问题
.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.
来源:https://stackoverflow.com/questions/1471205/how-can-i-get-reference-count-for-a-managed-object