0

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 ?

Rémi Doolaeghe
  • 2,262
  • 3
  • 31
  • 50

1 Answers1

1

If you explicitly null instance B then it will be Gc'ed

Chaffers
  • 176
  • 9