WMI4Java icon indicating copy to clipboard operation
WMI4Java copied to clipboard

Fix handle leak in Windows for Java >= 10

Open effad opened this issue 5 years ago • 0 comments

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.

effad avatar Feb 18 '20 13:02 effad