This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes static variables - kept on Heap or Stack Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "static variables - kept on Heap or Stack" Watch "static variables - kept on Heap or Stack" New topic

static variables - kept on Heap or Stack

jim gemlo

Joined: Feb 24, 2004
Posts: 20
Ok Instance variables are kept with their objects on the Heap but what about static instance variables? Where are they kept? Since there is one variable per class regardless of how many objects are created, are they stored outside of the object on the heap or are they put on the stack?
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
See this post with a very erudite answer from Ernest.

The short answer is, it depends. It's not the stack. It may be the heap, but technically it can't be. It's in some memory that the JVM has access to that isn't the heap. That's what I understood. Oh, and it doesn't matter.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: static variables - kept on Heap or Stack
It's not a secret anymore!