Hibernate out of memory exception while processing large collection of elements

后端 未结 4 1869
野性不改
野性不改 2020-12-18 05:25

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

4条回答
  •  心在旅途
    2020-12-18 05:57

    You have confused flushing with clearing:

    • flushing a session executes all pending statements against the database (it synchronizes the in-memory state with the database state);

    • clearing a session purges the session (1st-level) cache, thus freeing memory.

    So you need to both flush and clear a session in order to recover the occupied memory.

    In addition to that, you must disable the 2nd-level cache. Otherwise all (or most of) the objects will remain reachable even after clearing the session.

提交回复
热议问题