java.lang.OutOfMemoryError: Java heap space

0
Hi ,   I'm running a microflow in the acceptance environment and processing 1 lakhs records in that microflow. The microflow is breaking and throwing java.lang.OutOfMemoryError: Java heap space error. Can you please guide me how to resolve this issue. Also is there any way to increase the Java Object Heap space in the acceptance environment.   Thanks in advance
asked
4 answers
1

Try to set the following value:

app settings-> configurations-> edit -> server -> extra JVM parameter: -Xmx4096M or -Xms2048M according to your resource

answered
0

Abrar,

This error means you are trying to process too many records at once and the Java Virtual Machine runs out of memory.  One way to get around this error is to process the records in batches.  A development pattern I have used to do this is to add some attributes to the entity that I am processing:

  • Processed (boolean - default False)
  • Processed Date (datetime)

In the microflow that processes these records,

  • retrieve a certain number of unprocessed records by using Range > Custom in a retrieve action and use XPath [not(Processed)]
  • set the Processed boolean to true for each record you process and the Processed Date to current date time. 

After making those changes, you can run the microflow as many times as needed to process all records.

 

Hope that helps,

Mike

answered
0

The error java.lang.OutOfMemoryError: Java heap space was encountered while running a microflow in the acceptance environment that processes around 1 lakh records. When this error appears, it's basically indicating to us that the Java Virtual Machine (JVM) is lacking the allocated memory for object storage during execution.Inyour case, I sense that the large volume of data which is being handled by the microflow is most likely to cause excessive memory consumption, eventually leading to a heap space exhaustion.

 

To fix this issue, I will recommend you to first review and optimize the microflow. You know what, processing such a large number of records all at once may put significant pressure on the JVM heap. Instead of doing so, you can consider splitting the data into smaller, manageable batches and committing the results periodically will help in freeing up memory. Please make sure, there is no stacking up of unnecessary objects in memory which are no longer needed.

Checking and trying to increase the maximum heap size allocated to the JVM in the acceptance environment can also help accommodate the memory requirements. 

 

To know the cause of memory issues, tools like HeapHero or Memory Analyzer Tool (MAT) can be used. This actually will help you to inspect the heap dump and identify any potential memory leaks or objects consuming excessive space. For more context, you have checked this blog Types of OutOfMemoryError which gives an overview of different OutOfMemoryError scenarios and how to handle them effectively.

answered
0
  1. Processing 1 lakh (100,000) records all at once in a single microflow loads everything into heap simultaneously. The JVM simply runs out of space holding all those objects at once.

  2. Primary Fix: Process in Batches

Never process 100K records in one go. Break it into chunks:

Instead of:

Retrieve ALL 100,000 records → Process → OOM

Do this:

Retrieve 500 records → Process → Commit → Clear → Next 500


In Mendix microflow, use batch retrieval with offset:


Retrieve objects with limit: 500, offset: 0

Process batch

Commit and clear from memory

Retrieve next batch with offset: 500

...repeat

Secondary Fix: Increase Heap in Acceptance Environment


If processing data in batches and increasing the heap still doesn't eliminate the Java Heap Space error, it's worth investigating memory leaks or excessive object retention. This guide covers the common causes of Java Heap Space errors and practical approaches to diagnose and fix them: https://blog.heaphero.io/java-outofmemoryerror-heap-space/


answered