How to fix pmd violation “NullAssignment”?

女生的网名这么多〃 提交于 2019-12-02 09:59:47

This code is written in the false believe that a reference that is set to null is garbage collected faster.

Therefore the message from PMD is that this false believe was coded.

This is a wrong assumption as the garbage collector runs when the memory is exhausted and it collects all objects that have no reference left on them.

Even calling System.gc() will not cause the garbage collector to run. The call is merely a hint to the garbage collector but when the garbage collector detemines that enough free memory is avaible it will not run.

  Assigning an Object to null is a code smell.

IMHO

After setting the Object/variable to null you can call System.gc() which forces the garbage collector to run Right Now.

I believe there will be no violations and code smell in that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!