Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Var GC

 
Seth Anshul
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can static variables be garbage collected in Java?
 
Amit Y Desai
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if a static variable is set to null,then memory it references get garbage collected.

Useful note : Variables with the longest lifetime are static variables, you should be careful to assign null to any variable that are no longer used, especially if they reference large data structures.
 
Seth Anshul
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic