2 Replies Latest reply on Jun 28, 2011 7:25 AM by pgmjsd

    OOME with a Weld-SE object creation benchmark

    pgmjsd

      I was messing around with a DI container comparision with weld-se, Guice, PicoContainer and Spring and I ran across an issue with weld-se.




      What I want to do is have the DI framework repeatedly instantiate a POJO, with no dependencies (no injection points).   This will serve as the first phase of the benchmark, as I'll add injection points later.   This was very easy to do in Guice and PicoContainer, somewhat of a chore in Spring, but in Weld SE I was having a little trouble.   Anyway, I finally got weld to instantiate the POJO like this:


      WeldContainer weld = new Weld().initialize();
      weld.event().select(ContainerInitialized.class).fire(new ContainerInitialized());
      Instance<TestBean> instance = weld.instance().select(TestBean.class);
      TestBean bean = null;
      for (int i = 0 ; i < 100000; i++) {
          bean = instance.get();
      }
      



      The TestBean interface and implementation are very ordinary.   The implementation uses some singleton counters to count the number of instances the container creates:


      public interface TestBean {
          void action();
      }
      
      public class NoDepsImpl implements TestBean {
          public NoDepsImpl() {
              Counters.getInstance().incrementClient();
          }
      
          public void action() {
          }
      }
      



      In the other containers, this works fine, as the unreferenced beans are cleaned up by the GC fairly quickly.  Is there something hanging on to the instances of TestBean?  Is this the right way to repeatedly instantiate a POJO?