Declaring variable final and static

前端 未结 2 1908
自闭症患者
自闭症患者 2021-02-18 14:31

This comment was made in a code review and the person who made it is no longer on our team.

Any type that must be resolved by the classloader at runtime

2条回答
  •  别跟我提以往
    2021-02-18 14:48

    The comment is most likely related to a problem of Classloader Leaking (here is a good article).

    In a nutshell, this problem happens in environments where classloader needs to be reloaded. If you load a class dynamically through a classloader and then try reloading the classloader, keeping static final fields with objects of classes created through this classloader will prevent unloading the classloader itself. Once this happens, you get an OutOfMemoryError.

    The article linked above lists logging libraries among the top culprits that could produce this behavior, along with measures you can take to work around the leaks (such as releasing classloaders explicitly).

提交回复
热议问题