jProcesses icon indicating copy to clipboard operation
jProcesses copied to clipboard

Handle leak running in Windows

Open effad opened this issue 5 years ago • 4 comments

When running this code with Java 13 in Windows:

import java.util.List;

import org.jutils.jprocesses.JProcesses;
import org.jutils.jprocesses.model.ProcessInfo;

public class LeakTest {

	public static void main(String[] args) throws InterruptedException {
		JProcesses jpro = JProcesses.get();
		jpro.fastMode();
		while (true) {
			List<ProcessInfo> processInfos = jpro.listProcesses();
			Thread.sleep(100);
			System.out.println("Run " + System.currentTimeMillis());
		}
	}
}

the number of open windows (file) handles will grow constantly.

effad avatar Feb 07 '20 07:02 effad

The leak also occurs with JDK-1.8.0_202

effad avatar Feb 07 '20 08:02 effad

I think the actual bug is in com.profesorfalken.wmi4java.WMIVBScript.executeScript(String).

effad avatar Feb 07 '20 09:02 effad

By adding

                	process.getInputStream().close();
                	process.getOutputStream().close();
                	process.getErrorStream().close();

at the end of executeScript the leak can be made smaller, but it does not disappear altogether.

effad avatar Feb 07 '20 09:02 effad

By adding

                	process.getInputStream().close();
                	process.getOutputStream().close();
                	process.getErrorStream().close();

at the end of executeScript the leak can be made smaller, but it does not disappear altogether.

Yes it does disappear completely, but the Garbage Collector has to be run in order for the handles to be freed.

effad avatar Feb 18 '20 12:02 effad