Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java heap size error

 
Deepak Rajkiran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

I am facing a problem of java heap size .( memory out of ) . my all java class are singleton and method have local variables ,
Method local variables are four Map and two List . I call method by class instance on a jsp page with continuous ajax call with some another page. ..
after some time (mostly 5 hours)..i got jvm out of memory heap size error. I have alloted 64 MB memory to my tomcat .
When I used jProfiler for jvm memory hotspot , I found size of all variables increases exponentially .

please suggest how to optimize this jvm heap size error.
should i use some another design pattern and data structure. ?


 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out Of Memory error can come because of two reasons:

  • Application has such a number of in-use objects, the size of which is greater than the allocated heap size.
  • There is a memory leak


  • In the first case, increasing the heap size will be effective.
    On the other hand, increasing the heap size will be a temporary solution as the memory leak will somehow kill the application sooner or later.
    So, you need to find out whether you have memory leaks in your application. If yes, then you need to fix them rather than increasing heap size.

    Moving to performance forum.
     
    Omar Al Kababji
    Ranch Hand
    Posts: 357
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Deepak Rajkiran wrote:
    my all java class are singleton and method have local variables ,
    Method local variables are four Map and two List . I call method by class instance on a jsp page with continuous ajax call with some another page


    * I am just suggesting to double check your singleton code ... may be its not working as a singleton ... so i would suggest to put some kind of System.out.println() in the constructor of your singleton or use a logger to log this information. so that you we be sure that only one object is created.

    * I don't know what type of data you are storing in your maps and lists, however may be there is a possibility that you keep adding new objects even if in some cases there is no need to add them, it would be a good idea to clean your maps and lists from unnecessary data.

    except that i don't know may be your application really needs a bigger heap size.

    (peace)
     
    Peter Johnson
    author
    Bartender
    Posts: 5852
    7
    Android Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It does sound like you might have a memory leak. If you are using JDK 6, the [url=https://visualvm.dev.java.net/]VisualVM[url] can help you track down the memory leak - you can take two memory snapshots a few minutes apart and compare them - it will show you what objects increased in number. This can help you isolate the issue. (I know VisualVM can monitor JDK 5 apps, but I don't recall if you can get the heap snapshot.)
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic