Why didn’t we use CoRegisterInitializeSpy to clean up the unmarshalable delegate?
cppdashboard.dev/r/2026/10/why-didn-t-we-use-co-register-initialize-spy-to-clean-up-theThis article discusses the challenges and considerations of using CoRegisterInitializeSpy for cleaning up unmarshalable delegates in COM. It highlights issues related to thread management and the unpredictability of the unregistration process.
From the article
Another suggestion from Luca Bacci on creating a fake agile wrapper that is technically agile but is not useful outside its home apartment was to use the IInitializeSpy interface .
Some of the thing that made The RoRegisterForApartmentShutdown unsuitable also apply to CoRegisterInitializeSpy . For example, you are required to revoke the spy from the same thread that registered it, which means that we have to remember the original thread so we can somehow get back to executing code on it.
Another problem is explicitly noted in the documentation for CoRevokeInitializeSpy :
Share this resource