I am trying to process collection of heavy weight elements (images). Size of collection varies between 8000 - 50000 entries. But for some reason after processing 1800-1900 e
I don't know why you think committing a transaction frees heap memory. Running garbage collection does that.
OOM error can happen if your perm gen is exhausted.
The easy answer is to change your min and max heap sizes and perm gen size when you start the JVM and see if it goes away.
I'd recommending getting a profiler, like VisualVM, and seeing what is consuming your memory at runtime. It should be easy to fix.
I'd guess that you're trying to commit too large a chunk at once. Break it up into smaller pieces and see if that helps.