Q
qazmlp
import java.util.*;
class garbage_collection {
public static void main(String args[]){
System.out.println("Init");
for(int i = 0; true; i++) {
System.out.println(i) ;
String str = test1() ; // After this, will it be fully
garbage
// collected (10000 bytes) or only
6 bytes?
}
}
private static String test1() {
StringBuffer buff = new StringBuffer(10000); // Huge
StringBuffer
buff.append("Hello");
return buff.toString(); // The reference is returned here.
// So, not available for garbage
collection
}
}
Will 'buff' be completely garbage collected or only the bytes occupies
by the "Hello" will be GC-ed here?
Basically, I would like to know whether StringBuffer.toString() will
return the reference for the Complete 10000 bytes so that, it can be
garbage collected easily.
Thanks!
class garbage_collection {
public static void main(String args[]){
System.out.println("Init");
for(int i = 0; true; i++) {
System.out.println(i) ;
String str = test1() ; // After this, will it be fully
garbage
// collected (10000 bytes) or only
6 bytes?
}
}
private static String test1() {
StringBuffer buff = new StringBuffer(10000); // Huge
StringBuffer
buff.append("Hello");
return buff.toString(); // The reference is returned here.
// So, not available for garbage
collection
}
}
Will 'buff' be completely garbage collected or only the bytes occupies
by the "Hello" will be GC-ed here?
Basically, I would like to know whether StringBuffer.toString() will
return the reference for the Complete 10000 bytes so that, it can be
garbage collected easily.
Thanks!