Snippet 1:
start = runtime.freeMemory();
int i=1,j=2,k=3;
end = runtime.freeMemory();
System.out.println("That took " + (start-end) + " bytes.");
Snippet 2:
start = runtime.freeMemory();
int array[] ={1,2,3};
end = runtime.freeMemory();
System.out.println("That took " + (start-end) + " bytes.");
Assuming GC doesn't run inbetween the start and end variable assignments, Snippet 1 will also say 0 bytes used whereas snippet 2 will always have a non zero positive value - though both seem to have the same three numbers being created 1,2 and 3 - why?
Thursday, December 3, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment