Salve ragazzi..
ho un ciclo infinito che esegue questa funzione:

codice:
const SPPHRASE* speech::asr(string rule) {

	CoInitialize(0);

	hr = InitSAPI();

        //quà ci andrebbe il codice ma il problema si verifica già così...

	CleanupSAPI();

	CoUninitialize();

	return pParts;
}
E queste son le due funzioni che richiama:
codice:
HRESULT speech::InitSAPI() {

	hr = S_OK;

	while ( 1 ) {
        // create a recognition engine
        hr = cpEngine.CoCreateInstance(CLSID_SpSharedRecognizer);
        if ( FAILED(hr) ) break;
       
        // create the command recognition context
        hr = cpEngine->CreateRecoContext( &cpRecoCtx );
        if ( FAILED(hr) ) break;

		hr = cpRecoCtx->SetNotifyWin32Event();
		hEvent = cpRecoCtx->GetNotifyEventHandle();

        hr = cpRecoCtx->SetInterest( SPFEI(SPEI_RECOGNITION), SPFEI(SPEI_RECOGNITION) );
        if ( FAILED(hr) ) break;

        // Load our grammar, which is the compiled form of simple.xml bound into this executable as a
        // user defined ("SRGRAMMAR") resource type.
        hr = cpRecoCtx->CreateGrammar(1, &cpGram);
        if (FAILED(hr) ) break;

        // Set rules to active, we are now listening for commands
        hr = cpGram->SetRuleState(NULL, NULL, SPRS_ACTIVE );
        if ( FAILED(hr) ) break;

        break;
    }

    // if we failed and have a partially setup SAPI, close it all down
    if ( FAILED(hr) ) CleanupSAPI();

    return (hr);


}

void speech::CleanupSAPI() {

    // Release grammar, if loaded
    if ( cpGram ) cpGram.Release();

    // Release recognition context, if created
    if ( cpRecoCtx )
    {
        cpRecoCtx->SetNotifySink(NULL);
        cpRecoCtx.Release();
    }

    // Release recognition engine instance, if created
	if ( cpEngine ) cpEngine.Release();

}

sul main ho un for che esegue asr().. il problema è che a programma aperto.. la memoria continua ad allocare.. allocare... allocare.. che cosa sto sbagliando?