PMD report NullAssignment
of the following code, what is the best practice to fix it?
Assigning an Object to null is a code smell. Consider refactoring.
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.