We had multi-threaded application. Each thread has to invoke with CoIntialize when it is iniatialized as we use some C++ COM object for our DB operation. The application is working fine for longer time in the production env. But suddently the CoIntialize() API in thread init function failed with below error ThreadInit; HRESULT: 80070008 : Not enough storage is available to process this command. OS : Windows Server 2003 R2 with SP2. I found work a around in stackoverflow to increase heapsize for console application from 512 KB to 1MB in windows registry. I can do that. But I want to know what is the possible reason for this to happen first. The env did not changed recently. There are several other process running in that machine they can invoke Coinitialize without any issue. It failed for only two process. Thanks in advance
CoInitialize "initializes the COM library on the current thread", which does have a memory requirement.
My guess is that your production environment hit a point where the application's heap size was not adequate to initialize COM on the new thread. Perhaps you hit a scenario where you allocated more threads than previously, even if the application wasn't running as long.
Raising the heap size would fix this, since it would allow those threads to initialize properly.
Something is leaking somewhere. Start by assuming it is your program. You can observe its handle usage with Taskmgr.exe, Processes tab, View + Select columns and tick Handles, GDI objects and USER objects. Observe these numbers while your app is running. If they climb steadily then you're leaking handles in your code. The show is over once a column reaches 10,000.
A more obscure explanation is running out of space in the kernel memory pool. Also visible in Taskmgr from the Performance tab.
Is there any chance you call CoInitialize from DllMain, all the more, on DLL_THREAD_ATTACH? This would most likely cause a deadlock or lead to leaks.
I suppose a memory leak occurs somewhere around index of Thread Local Storage