Sorry but the comparison is between two tests that creates exactly the same number of panels. The other test was juste here to show that the problem only applies for panels, not for simple beans
We are dying a little bit more inside Spring with YourKit profiler and it seems that the difference is due to MethodInterceptor cache that is hold by CachedIntrospectionResults.
Here is a simpler test you can launch (you have to recreeate a new CachedIntrospectionResults class because the Spring one is private). You will see that there is 6x more memory consumes with CachedIntrospectionResults : I don't know why.
Code:
import java.beans.Introspector;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import javax.swing.JPanel;
import junit.framework.TestCase;
public class LaunchContextTest extends TestCase
{
private static final MemoryMXBean MEMORY_BEAN = ManagementFactory.getMemoryMXBean();
public void testJPanel()
{
MEMORY_BEAN.gc();
long memStart = MEMORY_BEAN.getHeapMemoryUsage().getUsed();
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
CachedIntrospectionResults.forClass(new JPanel() {}.getClass());
long memStop = MEMORY_BEAN.getHeapMemoryUsage().getUsed();
System.out.println("Test avec CachedIntrospectionResults sur beans simples : " + (memStop - memStart));
}
public void testIntrospector() throws Exception
{
MEMORY_BEAN.gc();
long memStart = MEMORY_BEAN.getHeapMemoryUsage().getUsed();
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
Introspector.getBeanInfo(new JPanel() {}.getClass());
long memStop = MEMORY_BEAN.getHeapMemoryUsage().getUsed();
System.out.println("Test avec Introspector sur beans simples : " + (memStop - memStart));
}
}