Forum Discussion

NewAutoTester's avatar
NewAutoTester
Contributor
7 years ago

java.lang.OutOfMemoryError: Java heap space error?

Hi,

I still get the java.lang.OutOfMemoryError: Java heap space even after updating JVM Options. 

export _JAVA_OPTIONS="-Xms4096m -Xmx4096m -XX:NewSize=256m -XX:MaxNewSize=356m -XXSmiley TongueermSize=256m -XX:MaxPermSize=356m"

 

ERROR:

Scenario Outline: Check for xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Given Prepare a transaction request for "xxxxxxxxxxxxxxxx" with setup user role as "xxxxxxxxx" transaction # StepDefinition.prepare_Transaction_Request(String,String)
java.lang.OutOfMemoryError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677)
at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:735)
at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:158)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
at java.util.stream.ReferencePipeline.forEachOrdered(ReferencePipeline.java:423)
at java.util.stream.ReferencePipeline$Head.forEachOrdered(ReferencePipeline.java:593)
at com.eviware.soapui.impl.support.loadsave.CompositeProjects.c(CompositeProjects.java:498)
at com.eviware.soapui.impl.support.loadsave.CompositeProjects.loadCompositeProjectFile(CompositeProjects.java:199)
at com.eviware.soapui.impl.support.wsdl.UrlWsdlLoaderPro.a(UrlWsdlLoaderPro.java:35)
at com.eviware.soapui.impl.support.wsdl.UrlWsdlLoaderPro.handleFile(UrlWsdlLoaderPro.java:27)
at com.eviware.soapui.impl.wsdl.support.wsdl.UrlClientLoader.load(UrlClientLoader.java:149)
at com.eviware.soapui.impl.wsdl.support.wsdl.UrlClientLoader.load(UrlClientLoader.java:127)
at com.eviware.soapui.impl.wsdl.support.wsdl.UrlClientLoader.load(UrlClientLoader.java:118)
at com.eviware.soapui.impl.wsdl.WsdlProjectPro.b(WsdlProjectPro.java:629)
at com.eviware.soapui.impl.wsdl.WsdlProjectPro.loadProject(WsdlProjectPro.java:421)
at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:314)
at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:293)
at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:288)
at com.eviware.soapui.impl.wsdl.WsdlProjectPro.<init>(WsdlProjectPro.java:208)
at com.stepDefinition.prepare_Transaction_Request(StepDefinition.java:76)
at ?.Given Prepare a transaction request for "xxxxxxxxxxxxxxxx" with setup user role as "xxxxxxxxx" transaction(xxxxxxxxx.feature:20)
Caused by: java.lang.OutOfMemoryError: Java heap space

 

Could you please help.

13 Replies

    • NewAutoTester's avatar
      NewAutoTester
      Contributor

      We run the project in 2 machines below are the RAM available in them.

       

      RAM:

      Linux Machine - 4 GB

      Windows Machine - 16 GB

      • jhanzeb1's avatar
        jhanzeb1
        Frequent Contributor

        I've seen this error before, I used to get this error while dealing with data-driven tests that required a lot of test data from an oracle DB in a short space of time. 

         

        What's the size of your XML file please? if it's over 20mb, I'd recommend splitting it into two and run the tests seperately. This was the case in free soapUI version. What SoapUI version are you using?

         

         

  • groovyguy's avatar
    groovyguy
    Community Hero

    NewAutoTester: Is this error coming from the Linux or Windows machine?

     

    On your Linux machine, setting the memory values to 4096 means you are allowing ReadyAPI to use ALL of your available RAM. It will not be able to do that, since the OS and other applications will need to use some RAM as well.

     

    On the Windows machine, I'd say you could safely set that value to 12288 instead of 4096 to see if it fares any better. That would be 75% of your 16GB of RAM which might work better for you. My testing machine has 32GB of RAM and I set my memory to 24576. 

     

  • The Java heap space error that you are facing actually indicates that your JVM is running out of memory to allocate for objects in the heap. Which means, the Java Virtual Machine (JVM) running is actually running out of memory allocated to the Java heap. Even though you have already increased the JVM options (-Xms4096m -Xmx4096m), this type of issue may come up if the application is holding on to objects longer than necessary.. or suppose if the workload by itself requires more memory than the configured. This is because, always, JVM by default does not utilize the full container memory unless we instruct to.

    On reviewing your stack trace, I get that the error occurs while processing transactions in parallel streams and during project loading in SoapUI (CompositeProjects.loadCompositeProjectFile). This suggests that a large amount of data is being processed or loaded into memory at once. 

    To overcome this, there are a few areas to consider,

    Suppose, if the issue continues even after increasing the heap size then it should be mainly because of the objects that will be retained unnecessarily in memory. This is actually an indication or a suggestion for a possible memory leak. In such scenarios, it is advisable to enable heap dump generation on OOM (XX:+HeapDumpOnOutOfMemoryError) and analyze the dump using tools like HeapHero to identify which objects are consuming the most memory.

    The next possibility could be when the application attempts to load very large files or collections into memory all at once. Yes, this action will actually overwhelm the available heap. This should be the logic behind any application. If any application tries to load large files all at once, definitely the available heap will overwhelm resulting in the “Java Heap Space” error .
    If you notice that the garbage collection is running frequently and not reclaiming space then it is a sign that the objects are still strongly referenced. So you can do an analysis for both heap and thread dumps together and get an understanding.

    In short, with the recommended steps you can first check your heap size configuration and increase the -Xmx value if needed. If the problem remains the same, then definitely you will have to analyze heap dumps to understand memory usage, with which  you can change your code to process large data sets more efficiently.

    You can check out this blog How to Solve OutOfMemoryError: Java heap space to understand more about this Java Heap Space error.