Closed
Description
Сursors in certain circumstances became useless, because hold all the data in the memory, causing OOM:
- on large number of rows fetched via one cursor (depends on Xmx)
- on any amount of data fetched via cursor, if that cursor is created and iterated sufficient number of times (e.g. fetch 1000 rows in a loop via different cursors N times (N depends on Xmx))
This happens because MyBatis:
- registers all cursors created within session and hold a hard reference to them (so they could not be garbage collected)
- cursor itself caches each row's data, when there is any nested result map, via hard reference
MyBatis version
3.5.11
Database vendor and version
PostgreSQL 13
Test case or example project
Steps to reproduce
Use result map with nested result map and fetch data via cursor
Expected result
The memory will be used at constant level
Actual result
The memory used as linear with fetched amount of data, i.e. more rows fetched via cursor - more memory is used