The Oracle Java Magazine contains an article about JavaFX design patterns, containing the following code:
while(!pointQueue.isEmpty()) {
PointPojo point = pointQueue.poll();
//coordinate transform data to canvas pixel
double x = transformXToScreen(point.x);
double y = transformYToScreen(point.y);
//encourage the object to be garbage collected sooner
point = null;
g.fillOval(x, y, radius, radius);
}
I can't see why the point = null
assignment would make the point object be garbage collected sooner. There variable is (re)assigned every loop, the loop doesn't block as it only runs as long as there is something to get.
Even if the loop would do a blocking call, the point
variable would move out of scope each loop iteration, so it would make the reference eligible for garbage collection.
What am I missing? Why would the article's author add this specific null
assignment?