Why are immutable objecs loved by JVM's GC?

后端 未结 3 1010
半阙折子戏
半阙折子戏 2021-01-02 10:23

I know the reason that JVM GC loves short-live object because it can be collected in minor GC. But why does JVM GC love immutable objects?

EDIT: Charlie Hunt says t

3条回答
  •  温柔的废话
    2021-01-02 10:50

    Thanks for the link..found it nice :)

    From presentation : GC loves small immutable objects and short lived objects.

    Edit:

    Smaller objects have short memory footprint which means that after collection there will not be much overhead on memory compaction ( Memory compaction is slow for big object as they leave bigger memory holes after they get reclaimed by GC). And short lived objects are also good as they get collected in minor GC cycles.

提交回复
热议问题