Java Collections and Garbage Collector

后端 未结 3 1231
执念已碎
执念已碎 2020-12-01 23:41

A little question regarding performance in a Java web app.

Let\'s assume I have a List listRubriques with ten Rubriqu

3条回答
  •  遥遥无期
    2020-12-02 00:17

    "Pretty soon" is a rather vague specification, but the garbage collector is probably not as swift as you seem to expect. When the objects actually will be collected depends a lot on the GC configuration and your server load, but it may take some time and if your VM has enough heap available and other things to do, the objects won't be collected "pretty soon".

    The only situation where the VM specification guarantees that the GC will run, is when at some point otherwise an OutOfMemoryError would be thrown. Before throwing an OutOfMemoryError, the VM is obligated to make an attempt to at least collect so many eligible object instances, that the relevant memory allocation request can succeed (but you're still not guaranteed that all eligible instances are collected).

提交回复
热议问题