1

Do variables and objects with the keyword final get picked up by gc? I assume this only happens when a final falls out of scope and there's no references left. Is that accurate?

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
  • Refer this [thread][1] [1]: http://stackoverflow.com/questions/306862/does-using-final-for-variables-in-java-improve-garbage-collection – MGK Dec 14 '11 at 17:06

3 Answers3

1

Yes. Final has no direct effect on GC.

(Arguably, it may delay GC slightly cause you can't assign null to a field).

user949300
  • 15,364
  • 7
  • 35
  • 66
1

Variables with the final keyword are treated the same as variables without the final keyword by the garbage collector. Therefore after the variable falls out of scope the garbage collector will clean it up next time it checks. You are correct

rogermushroom
  • 5,486
  • 4
  • 42
  • 68
1

Final should have no bearing on object lifetime.

GC will, at some time after there is no path from a GC root to an object, collect that object.

Greg Jandl
  • 831
  • 9
  • 12