i hava a c++ method(for java,jni) like follow,when i repeat call this from java (every 150ms),about after 4 hours. Memory overflow....
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;
}
}
The problem is this line of code:
advlib = NULL;
The advlib object needs the correct value in order to do its job. By destroying its value and setting it to NULL, it can no longer free the correct instance.
Uncommenting advlib.Release() will likely make it work. But the correct fix is to remove the advlib = NULL; and allow the CComPtr to do its job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With