0

My webapplication is occuring a memoryleak.(I monitored the webapp with visualVM)

Each time, I go on a specific jsf page which bean is annotated with ViewScope, the heap increase. With viewScope, all the objects (and memory) should be cleared when i leave the page. Even if I close the session, the heap stays at the same level and then increase again if i go on this jsf page...

So obviously the app will collapse... Does the session is not close well (does it should 'kill' all objects)? or is it possible that object references still persist and that garbage collector doesn't do the job ?

ZheFrench
  • 1,164
  • 3
  • 22
  • 46

1 Answers1

0

View lifetime management is JSF implementation specific. MyFaces and Mojarra implement a queue - when it gets full, then on the next creation of a new view some old one will be removed. The least recently used one, if I'm not mistaken. See BalusC's answer for additional specifics.

You can't reliably detect that a user has left the page. You can listen to window beforeunload events with js, but it won't work perfectly. I know that ICEfaces 1.8.2 does that.

When the session gets destroyed, then all its views get destroyed as well.

There are some problems with your expectations.

  • What do you mean by "close the session"? Even if you closed all browser windows, you still have to wait until the session times out. And even then it's not certain, web containers generally don't promise to immediately remove expired sessions. You can monitor session destruction through server log - for that you may need to tweak log settings of your specific server or create a HttpSessionListener.
  • The garbage collection does not promise that it will remove all unreachable objects immediately. Force a full GC via VisualVM a few times - that usually will be enough. But not 100% too.
Community
  • 1
  • 1
Vsevolod Golovanov
  • 4,068
  • 3
  • 31
  • 65