Chris Webster's Weblog
Memory Optimization Observation
I was looking at reducing the memory consumed by some of the full document fidelty models we have for WSDL and XML Schema. I noticed that one of the representations was storing an unnecessary object reference. I was expecting the object reference multiplied by the large number of objects created to have an impact on the memory size, but removing this reference did not have any impact. The basic code to illustrate this issue is below (I ran this using 1.5.0_06). What I noticed was that removing the member variable i from class T did not have any impact in terms of memory usage. However, uncommenting the j variable from Class T had the expected impact of increasing the memory size. The test code
import java.lang.management.ManagementFactory;
public class MemoryTest {
public static long getCurrentMemoryUsage() {
ManagementFactory.getMemoryMXBean().gc();
return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
}
static class Super {
public Super(String s) {
value = s;
}
public String getValue() {
return value;
}
private String value;
}
static class T extends Super {
public T() {
super(T.class.getName());
}
private int i;
//private int j;
}
public static void testNormalRef(Object[] list) {
for (int i = 0; i < list.length; i++) {
list[i] = new T();
}
}
public static void main(String[] args) {
final int numObjects = 100000;
Object[] refs = new Object[numObjects];
testNormalRef(refs);
long curUsage = getCurrentMemoryUsage();
System.out.printf("MemoryUsed %d\n", curUsage);
}
}
Posted at 10:19AM Mar 12, 2006 by Christopher Webster in Java | Comments[1]
JExamples.com Firefox search plug-in
There is now a Jexamples.com FireFox search plug-in on mycroft http://mycroft.mozdev.org/download.html?name=jexamples.com&submitform=Search. The plug-in allows searching from the firefox toolbar on Jexamples.com (which is a site for finding Java examples).Posted at 08:19AM Feb 04, 2006 by Christopher Webster in Java |
Sunday Mar 12, 2006