0
votes

I have a JSF application with a @ViewScoped bean. It is viewScoped because I do some ajax requests.

I load a big amount of data into the view and display it to the user.

Today I performed a load test and I ran into an OutOfMemoryException. As it turns out, when I open the page, @PostConstruct is called

bean created. ID = @54a35e23

Now I navigate to another page and return again (@PreDestroy was not called) Then I get

bean created. ID = @fee0948

I do this all over again in the load test. And a few hours later I have the OutOfMemoryException

Can I somehow force JSF to destroy my ViewScoped bean when I navigat to another page?

1
Do you use CDI or are you open to? OmniFaces @ViewScoped explicitly destroys beans and associated JSF view state during onload. But it requires CDI. See also showcase.omnifaces.org/cdi/ViewScoped - BalusC
I use java ee 6 and no CDI. Additionally I am very close to go live so I don't want to change lot. Is there no other way? - matthias
JSF (Mojarra) keeps a max of 25 view scoped beans in session. Alter memory space on that. Or, introduce 2nd level JPA cache (if you're using JPA). - BalusC
can I somehow reduce 25 to 3 ? - matthias
Not without hacking the impl. There's no public setting for that. - BalusC

1 Answers

0
votes

If you ViewScoped bean is huge, you have a problem with your implementation. Could you add your source to review it. If you're handling a huge data amount, you probably need to use something in memory grid like Infinispan or Hazelcast