domingo
abr012001
Cómo averiguar el tamaráo de un objeto
domingo, abril 1, 2001 at 2:00AM
C�mo averiguar el tama�o de un objeto
public class obj {
private String str = new String("ABCDE");
private int i;
}
class MemoryTest {
protected static final long COUNT = 100;
public static void main(String[] arg) {
long start, end, difference;
Object[] array = new Object[COUNT];
long i;
Runtime.getRuntime.gc(); // let's hope the
// garbage collector runs
start = Runtime.getRuntime().totalMemory();
for (i = 0; i < COUNT; i++) {
array[i] = new Object();
}
Runtime.getRuntime.gc();
end = Runtime.getRuntime().totalMemory();
difference = (end - start) / COUNT;
System.out.println("Approximately " + difference
+ " bytes used by 1 java.lang.Object with
default constructor");
}
}
in j2se
Reader Comments