static member variables lifetime
Hi,
I am wondering if anyone know what is the life time for a static variable. Let's say there is a class called Test and it has a static hashtable object as memeber called hashtest. something like this
Public Class Test {
public static hashtable hashtest;
}
Now when class gets loaded by classloader it will initialize static object but how long it will remain in the memory. Under what conditions values it contains may be lost? Does class also get garbage collected just like objets?
Thanks
-A.S.
[570 byte] By [
ashi70] at [2007-9-26 3:45:06]

The static variables last for the life of the program (unless, of course, the program changes the values).
I use this facility regularly for server programs that involve lots of file paths. Rather than have all these paths scattered through all the classes, I have a class - called Settings - with a lot of these paths available globally.
>The static variables last for the life of the program
Not exactly.
Static variables last until the class loader is unloaded. If there is no user defined class loader then the system class loader is used. And the system class loader is never unloaded. So for classes loaded via the system class loader that explaination is correct.