6 Replies Latest reply on Apr 22, 2014 2:19 AM by Jozef Hartinger

    MemoryLeak in javax.inject.Provider chain?

    Maxim Frolov Newbie

      Please take a look on three CDI Beans below:


      A.java:

      public class A {

          @Inject Provider<B> b;

      }

       

      B.java:

      public class B {}

       

      Main.java:

      @javax.inject.Singleton

      public class Main {

          @Inject private Provider<A> a;


          public void foo(@Observes ContainerInitialized event, @Parameters List<String> parameters) {

              while (true)

                  a.get();

          }

      }

       

      After each while loop in Main the number of A instances increases.

      The interesting point is: if A @Inject's B directly (without Provider), no memory leak occurs.

       

      My observation was: as soon as more that one @Inject Provider appears in a chain of injection points, the memory leak occurs.

       

      The same problem occurs in Weld-SE and in JEE6/7 environment on Wildfly and JBoss AS 7.1.3 if Main bean is a @Stateless EJB or a @Webservice.

       

      My questions are:

      1. Do I miss some basic understanding about using javax.inject.Provider?
      2. Or is this just a bug in Weld and I should create a bug ticket?

       

       

      In case somebody want to try it out, I uploaded a test maven project to GitHub:

      https://github.com/wrungel/bugs/tree/master/mleak-sales-ws