Is it safe to reuse the same variable to create another subprocess when the previous subprocess finishes?
String cmd = nextCmd();
while(waitForNext) {
Process p = Runtime.getRuntime().exec(cmd);
String iLine = null;
String eLine = null;
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while((iLine = in.readLine())!=null
|| (eLine = err.readLine())!=null) {
// just to clean the Streams
}
p.waitFor();
cmd = nextCmd();
}
will it be eligible for GC'd if the loop continues for thousand times(for example)?