Forum Stats

  • 3,874,957 Users
  • 2,266,788 Discussions


Java Heap Space - Out of memory issue

955690 Member Posts: 5
edited Aug 16, 2012 5:23AM in Java Native Interface (JNI)
Hi All,

We have 2 servers which has same heapsize setting (min and max 20 MB) and receives same load for processing.
But we receive heap memory issue in only one of the server.

Increasing the heap size only reduces the frequency of the occurence

What can be the possible causes ?

More details on the issue:*

The process invokes java calls via JNI and many instances of this process is configured with same settings in
both the servers. Both the servers are JDK1.6 configured.

The heap memory however is not reclaimed in one of the server. This issue is thrown while parsing XML to java object as shown below:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.reportStartTag(
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseAttributesNS(
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseOpenTagNS(
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseTagNS(
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseXMLNS(
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseXML(
at org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.yylex(
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yylex(
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yyparse(
at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(

Any inputs for resolving the issue will be of great help!


  • gimbal2
    gimbal2 Member Posts: 11,949 Gold Trophy
    A memory leak is a general case for heap space running out (note that 20mb is very low, that can't be correct). In Java a "memory leak" is the act of holding on to object references even after they are no longer used. It can also be caused by not calling some sort of close or cleanup method that is tied to native resources. Note that the XML thing can be a red herring, it is simply the spot that the JVM runs out of memory, it does not mean that it is the spot where memory is eaten up.

    A profiler tool can help you find out which parts of your application are eating up memory which will be a likely spot to find dodgy code; if you are using an IDE there may be a profiler built into it.

    And yeah there is always the possibility that the application during runtime simply needs more memory than you are giving it and you simply need to find the proper maximum heap space setting for things to remain stable. Setting min and max to the same number generally isn't a good idea, although that changes between garbage collector implementations.
  • 955690
    955690 Member Posts: 5
    thanks for your inputs.

    Yes, the exception thrown is only the point where jvm has run out of memory

    We had increased the setting to 70 MB in the server where this heap out of space is thrown.
    however only the frequency of this issue is reduced.

    Used jmap histo to analyze loaded Objects..It only highlights the char,string,byte objects instance that has consumed more memory. Couldn't derive solution from it..

    The code mostly nullifies objects in finally block. There are dynamically class loading mechanism Involved in few cases.

    The doubt is why it throws in one server and not in another, when the other parameters like JdK version, volume of orders it processes is approx same.?

    How to check if garbage collection is invoked at certain intervals? Any command/config setting to check the difference in JVM GC setting between the servers?

  • EJP
    EJP Member Posts: 32,939 Gold Crown
    edited Aug 14, 2012 7:32PM
    The code mostly nullifies objects in finally block.
    Then the code is poorly written, and it therefore probably exhibits numererous other fallacies as well, some of which may be causing excess memory usage. Nulling out local references in finally blocks accomplishes precisely nothing, and strongly suggests that the authors lacked competence.
  • 955690
    955690 Member Posts: 5
    Can you please elaborate on this --> exhibits numererous other fallacies as well, some of which may be causing excess memory usage.
  • gimbal2
    gimbal2 Member Posts: 11,949 Gold Trophy
    Let me translate: "The code sucks and probably has plenty of mistakes in it that lead to stability problems".

    Note that 70mb is STILL very low. I would expect something in the range of 128mb min - 256mb max for an average webapp to have enough breathing space.
  • 955690
    955690 Member Posts: 5
    Actually this is a java process configured with separate heap settings. Web app is configured with larger setting.

    the question is why same code runs out of memory in one server and not in another?

    Why is the leaky nature is reflected in only one box?
  • gimbal2
    gimbal2 Member Posts: 11,949 Gold Trophy
    952687 wrote:
    the question is why same code runs out of memory in one server and not in another?
    Different machine, different environment, simply not the same. So different behavior.

    Stop talking about leaks when you have no proof. Profile it and get some hard facts in stead of guesses.
This discussion has been closed.