-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeated calls to LSL.StreamInlet .info().channel_count() leaks memory #9
Comments
I'm not very good with Java, but the difference between the two snippets is that you're calling |
If you found the pattern in the first snippet ( |
The new float[], whether inside or outside the loop isn't a problem, The garbage collector can handle the extra allocations without problem. Allocating in the loop isn't great form. I've tested the following and it will show the memory leak as well. while (true) {
inlet.info().channel_count();
} Looking deeper into the code, the StreamInfo needs to be destroyed in order to avoid the leak. while (true) {
var info = inlet.info();
info.channel_count();
info.destroy();
} A better idiom here would be to have StreamInfo implement AutoCloseable. That way the IDE can let you know that you are not closing the resource. As the examples are written, they all leak memory by not destroying the StreamInfo. Albeit, they leak very little. A super quick look over the codebase shows there are Pointer objects in many places, all of which could represent a memory leak if they are not destroyed. |
Ah, I understand better now, thanks. |
The following code will leak memory
Whereas this works properly
I my experiment, I was collecting data at about 1 kHz. After an hour using the first snippet, my Java process was using about 20 GB. This obviously has an easy work around, but it does indicate that there is memory leaking somewhere (inside the native code?).
The text was updated successfully, but these errors were encountered: