accumulating thread count after calling mex file multiple times

I have written a mex function that opens a W32 window as a child to a matlab window. And a second function that closes this window.
After calling these functions repetitively (20+) without errors, matlab becomes unresponsive after 5 to 10 minutes. Even if i call drawnow in between the other calls. The only thing I notice is, that after each call to my mex functions the number of threads associated with matlab increases (>250).
I am not creating threads in my mex function and after creating a window in the first call, I reuse the handle to the window.
Question, why does matlab freeze after some time , and why is the number of threads increasing.
regards,
Chris

1 个评论

Without seeing the relevant part of the code, it is impossible to guess, what happens.

请先登录,再进行评论。

回答(1 个)

I've not put any code because it would have been too much, but I think I have solved the issue.
The thing is that in addition to creating a w32 window (which is no problem at all), I was using this as a directx render target.
IN the initializing call of the directX device I obtained a pointer to the back buffer, but forgot to release the pointer. This leads to a silent increase of thread use in matlab, which ultimately leads it to hang.
ID3D11Texture2D* pBackBuffer = NULL;
hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
if( FAILED( hr ) )
return hr;
hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
pBackBuffer->Release(); // * *critical part I forgot.**
if( FAILED( hr ) )
return hr;

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by