• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

static variables

 
Ranch Hand
Posts: 186
Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where do the static variables are stored in java...?
 
Saloon Keeper
Posts: 15630
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not exactly sure, but I believe they are stored in an instance of the Class class.
 
swaraj gupta
Ranch Hand
Posts: 186
Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi stephan,
thanks for the reply!

You mean to say on heap. Will you more elaborate your answer ?

Stephan van Hulst wrote:I'm not exactly sure, but I believe they are stored in an instance of the Class class.

 
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are stored in the Class object associated with that class. Instances of Class are also stored on the heap called "permanent generation".
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

amit mandal wrote:They are stored in the Class object associated with that class.



Can someone confirm this? Or some kind of material where we can read about this. Even I never thought about this But I feel they would also be on the heap- May be all the statics in one group on the heap? That's actually coming back to what Amit said

amit mandal wrote:Instances of Class are also stored on the heap called "permanent generation".



I believe that the Object allocation and GC techniques are much complicated. There's a new generation and an old generation. Objects are allocated to the new gen. if these objects survive the GC then they are moved to the old gen.
 
amit mandal
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can read it here even though its bit confusing :

permanent generation
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

amit mandal wrote:you can read it here even though its bit confusing :

permanent generation



Thanks for sharing the article
 
amit mandal
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mohamed sanaullah wrote:

amit mandal wrote:you can read it here even though its bit confusing :

permanent generation



Thanks for sharing the article



You are welcome
 
swaraj gupta
Ranch Hand
Posts: 186
Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have recently gone through an article on the same and according to that:
" Whenever a process is loaded in the RAM, we can say that the memory is roughly divided into three areas (within that process):
1> Stack
2> Heap
3> Static.
The Static which is also a part of heap is used for storing static members and is also called "High Frequency Heap."

But I have a doubt, if static members exist on heap then when does the garbage collector sweep them off the heap or it wouldn't consider them?
 
amit mandal
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

swaraj gupta wrote:I have recently gone through an article on the same and according to that:
" Whenever a process is loaded in the RAM, we can say that the memory is roughly divided into three areas (within that process):
1> Stack
2> Heap
3> Static.
The Static which is also a part of heap is used for storing static members and is also called "High Frequency Heap."

But I have a doubt, if static members exist on heap then when does the garbage collector sweep them off the heap or it wouldn't consider them?



I suppose the static variables reside inside the permanent generation part of the heap (which i suppose is same as the high frequency heap) and stays as long as their class objects remain there as dont forget for every class loaded the jvm creates an instance of Class. so as long as the Class object stays there, the static variable is safe from the GC.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

swaraj gupta wrote:But I have a doubt, if static members exist on heap then when does the garbage collector sweep them off the heap or it wouldn't consider them?



I think when ever the class is unloaded by the JVM.
 
swaraj gupta
Ranch Hand
Posts: 186
Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After all the discussion this is what I have concluded till now:
"There exist a separate space for static members (whether reference or variable) on the heap, which is freed when the class is unloaded by the JVM. And this reserved portion of heap for static members is never considered by Garbage Collector for garbage collection."

mohamed sanaullah wrote:

swaraj gupta wrote:But I have a doubt, if static members exist on heap then when does the garbage collector sweep them off the heap or it wouldn't consider them?



I think when ever the class is unloaded by the JVM.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic