I am using the LibusbJava.usb_bulk_write method on Windows. I have claimed the interface previously and I have a valid handle. Everytime I call it with a byte array of 2112 bytes the memory is never recovered. I can watch the available physical memory in my task manager continually drop in about 1.6Mbyte chunks. If I comment out the one line of code in my app that calls this bulk_write method, the memory leak goes away. When I try and profile the app in Netbeans I don't see the memory leak so I believe it is possibly at the driver level. I am calling the bulk_write method 2 million times in a tight loop. I looked at the source code for the driver and I don't see anything out of the ordinary. This is a show stopper and preventing me from devlivering my product on time. Any help would be appreciated. Here is a snippet of my code:
public synchronized void bulkWrite(byte[] data) {
if(handle != 0) {
int bytesWritten = LibusbJava.usb_bulk_write(handle, 4, data, data.length, 500);
}
}
thx in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The problem is that env->GetByteArrayElements is called but never followed up with a env->ReleaseByteArrayElements. When I call the bulk_write function over a million times I can watch the physical memory of my system become depleted and eventually my program crashes. When I add the ReleaseByteArrayElements the problem goes away.
Here is the code after my changes to just the bulk_write function as an example:
I have searched all my email and I can't find any email that contained the information you suggested so I am not sure what happened because I did receive the bug report email that I submitted and I have received the emails that contained the responses to this thread.
Anyway, thanks for the comment. I am glad I was able to help. It feels good to be able to give back once in awhile.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using the LibusbJava.usb_bulk_write method on Windows. I have claimed the interface previously and I have a valid handle. Everytime I call it with a byte array of 2112 bytes the memory is never recovered. I can watch the available physical memory in my task manager continually drop in about 1.6Mbyte chunks. If I comment out the one line of code in my app that calls this bulk_write method, the memory leak goes away. When I try and profile the app in Netbeans I don't see the memory leak so I believe it is possibly at the driver level. I am calling the bulk_write method 2 million times in a tight loop. I looked at the source code for the driver and I don't see anything out of the ordinary. This is a show stopper and preventing me from devlivering my product on time. Any help would be appreciated. Here is a snippet of my code:
public synchronized void bulkWrite(byte[] data) {
if(handle != 0) {
int bytesWritten = LibusbJava.usb_bulk_write(handle, 4, data, data.length, 500);
}
}
thx in advance.
I have downloaded the source code, modified it, and verified that there is a memory leak in the following 3 functions:
Java_ch_ntb_usb_LibusbJava_usb_1control_1msg
Java_ch_ntb_usb_LibusbJava_usb_1bulk_1write
Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1write
The problem is that env->GetByteArrayElements is called but never followed up with a env->ReleaseByteArrayElements. When I call the bulk_write function over a million times I can watch the physical memory of my system become depleted and eventually my program crashes. When I add the ReleaseByteArrayElements the problem goes away.
Here is the code after my changes to just the bulk_write function as an example:
JNIEXPORT jint JNICALL Java_ch_ntb_usb_LibusbJava_usb_1interrupt_1write
(JNIEnv *env, jclass obj, jlong dev_handle, jint ep, jbyteArray jbytes, jint size, jint timeout)
{
clearLibusbJavaError();
jbyte *bytes = env->GetByteArrayElements(jbytes, NULL);
jint num_bytes = usb_interrupt_write((usb_dev_handle *) dev_handle, ep, (char *) bytes, size, timeout);
env->ReleaseByteArrayElements(jbytes, bytes, 0);
return num_bytes;
}
fixed in the newest release
You're welcome.
I guess you don't read the e-mails sent to your e-mail address which is registered for bbergeson8?
18.12.2008 22:43 -> I wrote that I have reproduced the problem and sent you a corrected DLL
But anyway: THANK YOU VERY MUCH that you have pointed out the problem!
You're welcome.
I have searched all my email and I can't find any email that contained the information you suggested so I am not sure what happened because I did receive the bug report email that I submitted and I have received the emails that contained the responses to this thread.
Anyway, thanks for the comment. I am glad I was able to help. It feels good to be able to give back once in awhile.