更新:2007 年 11 月
当公共语言运行库 (CLR) 调用 ICorProfilerCallback 接口中的某些方法时,运行库将无法执行垃圾回收,直至探查器从该调用返回控制为止。这是因为分析服务无法始终使堆栈处于可以安全进行垃圾回收的状态。因此,在回调过程中将禁用垃圾回收。在这些情况下,探查器应尽快返回控制。下列回调将会出现此情形:
ICorProfilerCallback::ExceptionOSHandlerEnter、ICorProfilerCallback::ExceptionOSHandlerLeave
ICorProfilerCallback::ExceptionUnwindFunctionEnter、ICorProfilerCallback::ExceptionUnwindFunctionLeave
ICorProfilerCallback::ExceptionUnwindFinallyEnter、ICorProfilerCallback::ExceptionUnwindFinallyLeave
ICorProfilerCallback::ExceptionCatcherEnter、ICorProfilerCallback::ExceptionCatcherLeave
ICorProfilerCallback::ExceptionCLRCatcherFound、ICorProfilerCallback::ExceptionCLRCatcherExecute
ICorProfilerCallback::COMClassicVTableCreated、ICorProfilerCallback::COMClassicVTableDestroyed
此外,下列回调允许探查器通过使用 fIsSafeToBlock 参数逐个调用阻止垃圾回收:
请注意,如果探查器进行了阻止,它将延迟垃圾回收。只要探查器不调用触发垃圾回收或在托管堆中分配空间的 CLR 函数,这种延迟就无关紧要。