Opencv Camera Open issue(memory leak)

int videoInput::start(int deviceID, videoDevice *VD){



VD->myID = deviceID;

VD->setupStarted = true;

CAPTURE_MODE = PIN_CATEGORY_CAPTURE; //Don't worry - it ends up being preview (which is faster)

callbackSetCount = 1; //make sure callback method is not changed after setup called


if(verbose)printf("SETUP: Setting up device %i\n",deviceID);



// Create the filter graph manager and query for interfaces.

hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&VD->pCaptureGraph);

if (FAILED(hr)) // FAILED is a macro that tests the return value


if(verbose)printf("ERROR - Could not create the Filter Graph Manager\n");

return hr;




// Create the Filter Graph Manager.

hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void**)&VD->pGraph);

if (FAILED(hr))


if(verbose)printf("ERROR - Could not add the graph builder!\n");


return hr;


Regardless of the version, the memory and handle will increase when a single camera is opened(), read(), or release() (Test versions 4.5.4 and 2.4.12).

There is a problem when using vidocapture in cv. If you repeat Open(), Read(), Release(), and later go through the filter graph manager, the current process has used allow all handles of Window Manager objects. This error occurs.

ERROR_NO_MORE_USER_HANDLES (1158-0x00000486) occurs…

it is the cv itself a memory leak? or directshow memory leak?

Is there any way to solve this problem?

that code contains no calls to OpenCV APIs. if you need support for WinAPI, I’d suggest the MSDN forums. and out of the blue you talk of a “steering wheel”. please clarify.

sorry im changed sorry