I have an application doing a lot of string manipulation, and I noticed that the jvm memory usage is very high while I'm not even storing anything in memory.
I made a sample application to demonstrate the issue : I have a simple JFrame with one button
private void buttonDoWorkActionPerformed(java.awt.event.ActionEvent evt) {
String randomString = "abc test garbagecollector";
ArrayList<String> results;
for(int i=0; i<100000; i++)
results = doNothing(randomString.split(" "));
results = null;//No effect
System.gc();//No effect
}
private static ArrayList<String> doNothing(String[] words) {
ArrayList<String> results = new ArrayList<String>();
for (String word : words)
results.add(word);
return results;
}
If you run this sample the JVM takes about 50Mo in the memory, and once you hit the button it will raise to 150Mo and will never go down. EDIT : I am refering to the "java.exe" process in the windows task manager.
Obviously I'm doing a lot of temporary string copies, but I excpect them to be freed by the carbage collector once I lose the references.
EDIT: Maybe not related but I tryed with java 1.6 both 32 and 64 bits versions.