我有一个 c++ 方法(对于 java,jni),就像下面一样,当我从 java 重复调用这个(每 150 毫秒)时,大约在 4 小时后。内存溢出……
JNIEXPORT jint JNICALL Java_nc_mes_pub_hardware_PCI1761_readChanel (JNIEnv *, jobject, jint channel){
HRESULT hr ;
CLSID clsid;
hr = CLSIDFromProgID(L"AdvDIO.AdvDIOCtrl", &clsid);
CComPtr<IAdvDIO> advlib;
hr = advlib.CoCreateInstance(clsid);
if ( SUCCEEDED( hr ) )
{
advlib->DeviceNumber = 0;
if(advlib->DeviceNumber < 0){
return -100;
}
int i =advlib->ReadDiChannel( channel );
// advlib.Release();
advlib = NULL;
return i;
}
else
{
return -1;
}
}