Yes, you’ll need to batch these up so that the commits are occurring in separate transactions. If you’re performing the work in an iterative microflow, you can use the StartTransaction and EndTransaction Java actions from the Community Commons module to control the transaction behavior.
This is a runtime error in Java which occurs when you allocate a new object in your application over a period of time continuously and the Garbage Collector (GC) cannot make space available to accommodate a new object, and the heap cannot be expanded further, which resulted this error.
Therefore you pretty much have the following options:
Increasing the heap size is a bad solution, 100% temporary, because you will hit the same issue if you get several parallel requests or when you try to process a bigger file. To avoid OutOfMemoryError, write high performance code: