my dog learned polymorphism
The moose likes Beginning Java and the fly likes Static variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static variable" Watch "Static variable" New topic

Static variable

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Dear all,
When are static variables eligible to garbage collection?
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Static variables are garbage collected when the class they belong to is garbage collected. Classes can only be collected when nothing refers to that class anymore.
kind regards
John Wetherbie

Joined: Apr 05, 2000
Posts: 1449
If the static variable is being used by a number of objects then it is eligible for GC when the last object using it is GC'd.

The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
I agree. Here's the link:
subject: Static variable
jQuery in Action, 3rd edition