PRB: Problems When You Call CoInitialize and CoUninitialize Repeatedly in Multithreaded Apartment (293278)



The information in this article applies to:

  • Microsoft COM

This article was previously published under Q293278

SYMPTOMS

If you call the CoInitialize and the CoUninitialize functions repeatedly in a multithreaded apartment, you may notice the following:
  • Problems in the application that makes such calls.
  • High memory and a high event handle count for the process.
  • Delays when you shut down the apartment while you exit the process. When this occurs, the process may appear to stop responding (hang).

CAUSE

This behavior occurs because, during CoUninitialize, every proxy that is created is released by a remote Release call. If this Release does not return for some reason, the call times out. This is repeated for all the proxies. Therefore, the process appears to hang.

RESOLUTION

Microsoft does not recommend that you call CoInitialize and CoUninitialize pairs repeatedly in a multithreaded apartment (MTA). After the multithreaded apartment is created, Microsoft recommends that you keep the multithreaded apartment initialized until you exit the process.

STATUS

This behavior is by design.

Modification Type:MajorLast Reviewed:9/24/2002
Keywords:kbDCOM kbDSupport kbGuidelines kbprb KB293278