File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes java heap size error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "java heap size error" Watch "java heap size error" New topic
Author

java heap size error

Deepak Rajkiran
Greenhorn

Joined: Feb 10, 2008
Posts: 6

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

Joined: Feb 25, 2007
Posts: 1638

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.

    apigee, a better way to API!
    Omar Al Kababji
    Ranch Hand

    Joined: Jan 13, 2009
    Posts: 357
    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)


    Omar Al Kababji - Electrical & Computer Engineer
    [SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
    Peter Johnson
    author
    Bartender

    Joined: May 14, 2008
    Posts: 5836
        
        7

    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.)


    JBoss In Action
     
    GeeCON Prague 2014
     
    subject: java heap size error