0 Replies Latest reply on Mar 8, 2006 11:27 PM by Clebert Suconic

    MemoryLeaks test Testsuite

    Clebert Suconic Master

      It's possible to use JVMTIInterface (JBossProfiler JNI wrapper for JVMTI) to create testcases validating memory leaks (like redeployment issues).

      For example you could create a testcase that executes a bunch of ClassLoader operations, release the references in your testcase, and do a simple assertion if the JVM is clean for that particular class.

      Notice the call to forceGC() on my example at the end of this e-mail (which calls a FullGC no matter what you pass as a parameter on the VM, since this *is not* calling System.gc), and the assertions I'm doing. This is a nice way to query loaded objects and do assertions about them.

      I have that need since I will be now testing WeakHashMaps or SoftReferences within JBossSerialization, and I will need to make I'm not leaking redeployments.

      So, if you want to, you could create a separated testsuite ensuring that a memoryLeak is not going to be introduced again once you have it tested.

      Well... This is just an idea. Any thoughts?

      This is an example that is working on my workspace. The only thing I had to do was to add -agentlib:jbossAgent as a VM argument. This testcase is passing without any problem:

      package org.jboss.test;
      import org.jboss.profiler.jvmti.JVMTIInterface;
      import java.util.*;
      import junit.framework.TestCase;
      public class SomeTest extends TestCase {
       public void testAllocations()
       JVMTIInterface jvmtiInterface = new JVMTIInterface();
       ArrayList list = new ArrayList();
       for (int i=0;i<=100;i++)
       list.add(new TestPojo("index=" + i));