JSF: Mojarra vs. OmniFaces @ViewScoped: @PreDestroy called but bean can’t be garbage collected

The cause of this problem seems to be due to strange behaviour JVisualVM when attached to Glassfish/Payara.

The test case used for this question is still extremely useful, however the conclusions concerning Garbage Collection in the original post (and images) were based on JVisualVM, and I have since found they are not valid.

Use the NetBeans Profiler instead !

I am now getting completely consistent results for OmniFaces ViewScoped with the test app on forcing GC from within the NetBeans Profiler (with 1 omnifaces view scoped bean left per open tab).

When using JVisualVM attached to GlassFish/Payara I am getting references still held (even after @PreDestroy called) by field sessionListeners of type com.sun.web.server.WebContainerListener within ContainerBase$ContainerBackgroundProcessor, and they won’t GC.

The image shows a screenshot of JVisualVM attached to Payara with only 1 tab open but still 9 OmniViewBean instances held, no matter how often GC is forced.

Screenshot of JVisualVM attached to Payara with only 1 tab open but 9 OmniViewBean instances held


Updated results table using Mojarra-2.3.0 vs OmniFaces-2.6.6 in NetBeans IDE 8.2 Profiler

Updated results table using Mojarra-2.3.0 vs OmniFaces-2.6.6 in NetBeans IDE 8.2 Profiler

Updated test app sequence:

home


JSF2.0 @ManagedBean @ViewScoped


JSF2.3 @Named @ViewScoped


OmniFaces 2.6.6 @ViewScoped with @Named


Leave a Comment