By tracing down a classloader leak in my TomEE webapp I created a minimalistic app (one JSF Page, one class) and realized, that this already creates a classloader leak.
Leaks are introduced for example when: * enums are used * certain lambdas are used (see code example) * CDI scopes are used (see code example) * a beans.xml is provided * ...
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named // no leak
@RequestScoped // introduces a leak!
public class PrincipalTest {
public String userName() {
return "User name from bean.";
}
// some lambdas will remain instanciate after app is stoped
public List<String> names(){
List<String> list = new ArrayList<>();
list.add("aaa");list.add("abb");list.add("acc");
// this lambda implementation is fine:
return list.stream()
.filter(s -> s.startsWith("a"))
.collect(Collectors.toList());
// this introduces a leak:
// return list.stream()
// .collect(Collectors.toList());
}
I'm substantially confused about this and feel like having no chance to ever get a 'real' app class-leaking free. What are your experiences?
Can anybody confirm this behavior? (I uploaded my test sources to https://1drv.ms/u/s!AlHB9FAlFWW_iLkHPeUguiu2HSZ8FA?e=2eiBHM - in case someboy likes to play with it.)