Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static and gc

 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set a static variable to a value but you don�t instantiate an object for that class: What�s the lifetime for your set value?
Eg: Putting the following sentence in my main method

Locale.setDefault(Locale.FRENCH)
What�s ensure me that when I instance a Calendar object in any object of my application, my default Locale will be the one I�ve set.

[This message has been edited by Marcela Blei (edited June 30, 2000).]
 
Adrian Ferreira
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcela,

From API about setDefault method:
"Sets the default locale for this instance of the Java Virtual Machine."
So, as Locale.FRENCH, creates an instance of Locale class, this object can not be collected by GC until the end of the program.
Now about static an GC:
Static class or value can not be collected by GC. They are defined at compile time and are attached to class code. GC exists to free memory alocated during execution time for class instances (objects).
Hope it helps!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic