jProcesses
jProcesses copied to clipboard
Handle leak running in Windows
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.
The leak also occurs with JDK-1.8.0_202
I think the actual bug is in com.profesorfalken.wmi4java.WMIVBScript.executeScript(String)
.
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.
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.