[
https://issues.jboss.org/browse/AS7-5586?page=com.atlassian.jira.plugin.s...
]
Stan Silvert commented on AS7-5586:
-----------------------------------
I'm afraid you won't like this answer, but this is working as per spec. I misread
Ed Burn's comments before. @PreDestroy is actually not called on session invalidation
for @ViewScoped beans. That's what the spec change is asking for.
Here is the spec request to change this in JSF 2.2:
http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-905
So this does work if you navigate to another view via postback. And that's the only
condition on which a @PreDestroy is actually called. It has to go through the
NavigtionHandler and call FacesContext.setViewRoot().
To see it working, just add this to the view scoped bean:
{code}
public String goHome() {
System.out.println("... going back to index.xhtml ...");
return "index";
}
{code}
And add a form and a submit button to indexView.xhtml:
{code:xml}
<f:view>
<h:form>
blah blah blah
<h:commandButton value="GoTo request-scoped test"
action="#{injectionBeanView.goHome}"/>
</h:form>
</f:view>
{code}
So if you hit the button to go back to index.xhtml then @PreDestroy will get called. To
see this, I just put a System.out.println() in my @PreDestroy method.
Unfortunately, all this makes ViewScoped beans a bad choice if you need to release
resources. You can't guarantee that the view will be ended through normal navigation.
Hopefully, this will indeed be fixed in JSF 2.2.
@PreDestroy not called on view scoped managed bean
--------------------------------------------------
Key: AS7-5586
URL:
https://issues.jboss.org/browse/AS7-5586
Project: Application Server 7
Issue Type: Bug
Components: JSF
Affects Versions: 7.1.1.Final, 7.1.2.Final (EAP)
Environment: Initializing Mojarra 2.1.7-jbossorg-2 (20120412-0335) and all native
Jboss JSF impl
Reporter: Mauricio Fenoglio
Assignee: Stan Silvert
Labels: jsf2, jsf21, memoryleak
Attachments: InjectionTest.jar, InjectionTest.war, InjectionTest.war,
InjectionTestV2.jar, TestingJSFMemoryLeak-1.0-SNAPSHOT.war
All JSF ManagedBean are not destroyed and generate a great memory problem.
This happen for View Scopes
Nor are running @PreDestroy
It is not possible to have production environments with jsf, so it is a blocker issue.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:
http://www.atlassian.com/software/jira