Details
-
Improvement
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
1.1.2
-
None
Description
See https://issues.jboss.org/browse/CDI-139 for the problem.
Consider the following code:
@Dependent
public class MyClass {
...
}
private @Inject Instance<MyClass> inst;
public void doSomething() {
MyClass dings = inst.select(...).get()
}
The problem here is that the @Dependent MyClass doesn't get injected into some other class, thus it doesn't share any lifecycle. Thus it will never get destroyed properly, and it's mem will also not get freed.
The proper solution to that (as I explained in CDI-139) is to store T, the CreationalContext<T> and Contextual<T> which got used to create T in a List and destroy them properly via a @PreDestroy in Instance<T>