I have a sample project with more than 2000 tables. When I use Mybatis to load it, and then analyze dump through MAT tool, I find that the memory footprint is very high. Is this a normal phenomenon?

MyBatis version

3.x.x

Database vendor and version

mysql 8.0

Test case or example project

snapshot: MyBatis Suspected high memory footprint MyBatis Suspected high memory footprint MyBatis Suspected high memory footprint MyBatis Suspected high memory footprint

MyBatis Suspected high memory footprint MyBatis Suspected high memory footprint

demo2.zip: demo2.zip

MAT: https://eclipse.dev/mat/

Comment From: harawata

Hello @youngledo ,

Well, if there are many mappers, MyBatis needs more memory to store them, obviously.

IIRC, sqlFragments are not necessary once all mappers are loaded, however, in the current design, developers can add mappers anytime they want (i.e. there is no "finished" state), so we cannot clear it automatically.

DefaultReflectorFactory has a flag classCacheEnabled that disables the internal cache, so you can give it a try if memory consumption is your biggest concern. It can have negative impact on execution speed, though.

If you find a place where MyBatis uses unnecessary memory, please let us know the details.