You can follow Calculate size of Object in Java answer.
But if you have memory problem most probably better solutions can be:
- Maximize memory heap
- Use a
ScrollableResults
to avoid all memory issues
I prefer solution number 2 because it is definitive; the first one can still cause memory problem.