0

I've recently moved to myfaces with tomahawk (following this successful thread link), and I'm getting out of memory errors whenever I'm writing new code and the application (Tomcat) reloads the context. This is the generic reload message: "INFO: Reloading Context with name [/Auctions] has started"

And it's followed seconds later by this: "Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space"

I know that I can increase the memory (btw., should it be done directly in Tomcat, or somewhere in Eclipse?) but this out of memory error used to pop up only after several reloads, and now it slows down my development.

Also, I'm obviously concerned about deployment.

What should I do?

EDIT:

One thing that seems related: I'm getting 2 warning messages like this:

"WARNING: Cannot serialize session attribute auctionsViewBean for session CB0149C43DF44F5AA6A084A022F1D418" 

immediately followed by

java.io.NotSerializableException: org.apache.catalina.session.StandardSessionFacade. 

And then the out of memory error happens.

Now, AuctionsViewBean implements Serializable, but I'm reading here that a bean may not be re-serialized into the session unless it has a no argument constructor. My bean does have a no argument constructor, but I am setting some values in it. Could this cause the problem?

If so -- and in any case, really -- what is the best place for setting values into a bean? Is it in the constructor, or somewhere else in its lifecycle?

Community
  • 1
  • 1
Herzog
  • 923
  • 1
  • 14
  • 28
  • http://wiki.apache.org/tomcat/OutOfMemory – BalusC Nov 29 '11 at 14:11
  • Thanks, BalusC. Nothing jumps out of the page here, but I looked into it some more and edited the question. – Herzog Nov 29 '11 at 15:16
  • That link explains how this kind of errors are been caused and how they are supposed to be solved. The root cause of the problem is not in Tomcat itself, but in the webapp itself. In your case, it seems to be caused by MyFaces and/or Tomahawk. – BalusC Nov 29 '11 at 15:19
  • This is a old known problem, which was discussed and solved long time ago. I'll answer the question with more details. – lu4242 Nov 29 '11 at 19:11
  • Well, it seams like I can't answer my own question because I was "downgraded." Great. Anyway I'll try commenting with the relevant info: The problem is solved. I'll try to describe the process because I'm not sure about the first thing I did (I'm absolutely not a JSF 2 expert.) From what I read on the subject all the beans, and the model objects, need to implement serializable, and have a no argument constructor. It also helps not to have a reference to the session as an instance variable on the beans. (... continued below...) – Herzog Dec 05 '11 at 14:24
  • (...continued) When I followed the steps above the "serializable" exceptions went away, which cleaned up my log by a lot. But the out of memory errors, when the context is reloaded, continued. They finally went away when I changed the My Sql Java connector from an older version to the latest one, which is mysql-connector-java-5.1.18-bin.jar. The application now reloads without any issues. – Herzog Dec 05 '11 at 14:24

1 Answers1

0

I remember this question on MyFaces users list long time ago. The warnings happens because you have a session bean and that bean does not implements serializable. When the context is reloaded, Tomcat try to serialize everything inside session scope, causing the problem.

It is possible to cause an java.lang.OutOfMemoryError restaring an application multiple times, but this is caused because Tomcat load and unload classes from its classloaders, so it will happen anyway. Long time ago, some issues were found that causes a memory leak MYFACES-3158, MYFACES-3001, MYFACES-2942, but note those issues were solved. The problem in that time was caused because there was some references that does not allowed the GC to reclaim tomcat webapp classloader.

lu4242
  • 2,318
  • 1
  • 15
  • 15
  • Thanks, lu4242. Actually, all my beans implement Serializable. I'm reading [here](http://old.nabble.com/NotSerializableException:-StandardSessionFacade-td16758759.html) that they should also have a no-args constructor. All of them do, in my application, but some of them set a couple of variables and I have a hunch that this is causing the problem. What do you think? Also, if I can't set variables in the constructor, where should I do it? Maybe in preRenderView()? Or somewhere else in the bean's lifecycle? – Herzog Nov 30 '11 at 09:08
  • Quick update: the serializable problem came because I had a reference to the session in the bean's constructor. I removed it, and also moved the initialization code from the constructor to a @PostConstruct method. The serialization exceptions are gone. The out of memory errors are still here whenever I change the code and the context is reloaded. – Herzog Nov 30 '11 at 17:35