• Post Reply Bookmark Topic Watch Topic
  • New Topic

Static Var GC  RSS feed

 
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..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!