-3

I am programming a Java application allowing to minimize any boolean expression using QuineMcCluskey methodology. When I compile my code, I have an OutOfMemory Error with the message "Java heap space"!

If I understand, the exception may have several origins:

  • The memory space allocated to the JVM heap is insufficient to create the objects required by the application.

  • A memory leak prevents the garbage collector from releasing objects that are yet unused but still have references. Thus these objects are never released and occupy more and more space in the pile until occupying all the available space.

  • ...

I know that use a profiling tool may be necessary to analyze the contents of the memory of the JVM and determine the origin of the memory consumption. But how use thoses tools ? Have I to modify xmx and xms data ? What could be the consequences if I change them ? (I know also that it is necessary to optimize my code).

What are the different debugging steps ?

Furthermore, this application has to be use by lot of users (so by diferent computers...)

As you can see, I have lot of questions about this problem (I am a novice lol)... That's why I create this post.. I would like to resolve this problem by the better way and also, learn good reflexes.

Thank you!

Bigote
  • 95
  • 7

2 Answers2

1

Increasing of the memory is NOT the solution, unless you have unlimited resources!

If that happens in production or any machine other than your own, you can force the JVM which runs your service to generate a dump file which you can then download and analyse by adding VM flag -XX:+HeapDumpOnOutOfMemoryError to your jvm.conf file.

That is pretty useful when the machine that runs the app becomes unresponsive so no JMX connections could be made in order to run Oracle's JMC (or similar) monitoring tools. If you are for some reason able to get to the VM you can run the flight recording and try to analyse which method is causing the OOM.

Check here how to use flight recording.

And check this for heap dump analysis preview

kiselitza
  • 119
  • 8
  • 1
    If you're running on JDK11 or later you can also make use of the Flight Recorder Old Object Sample event to investigate potential memory retention issues. http://hirt.se/blog/?p=1055 – Henrik Dafgård Apr 26 '19 at 15:01
0

It is possible to increase heap size allocated by the JVM by using command line options Here we have 3 options

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size

 java -Xms16m -Xmx64m ClassName

It is also possible to increase heap size allocated by the JVM in eclipse directly In eclipse IDE goto

Run---->Run Configurations---->Arguments

And set VM arguments

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
abj1305
  • 635
  • 9
  • 21