WMI4Java
WMI4Java copied to clipboard
Fix handle leak in Windows for Java >= 10
As discussed in https://github.com/profesorfalken/jProcesses/issues/32, there is a handle leak when using WM4Java for Java versions beyond 10. This PR works around the problem by explicetly closing the streams of process.
Here's a Test that can be executed to demonstrate the problem:
public void testWindowsHandleLeak() {
JProcesses jprocesses = JProcesses.get().fastMode();
for (int i = 0; i < 1000; i++) {
jprocesses.listProcesses();
System.gc();
System.out.println("#" + i);
}
}
when run one can see in the task manager that the handles of the javaw executable go up all the time. After the fix is applied, handle count stays stable.