11 Replies Latest reply on Dec 6, 2013 3:47 AM by Martin Kouba

    Weld : How to make injected objects with Instance<> being garbage-collected

    Rémi Doolaeghe Newbie

      My question will be quite simple : How to avoid JBoss Weld (1.1.5) to keep references to objects produced by Instance ? Typically, the following code :

      class B{}


      class A {

           @Inject

           private Instance<B> instanceB;

       

           public B produce(){ return instanceB.get();

      }

      If I call A#produce(), then the B object won't be garbage-collected before the A object is garbage collected.

      Is there any workaround to make it possible for the B object to be garbage-collected, without the A object been garbage-collected ?