• Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory Managment  RSS feed

 
Jack clouseau
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have some doubt regarding the memory management in Java. And my doubt is where do the Static and Instance methods reside, is it in heap or in the Stack?

Thanks...
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Methods are neither in the heap nor the stack. Methods consist of executable code, which is in a memory location separate from the data (variables etc.) that your program is using.

Objects are always on the heap.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
Objects are always on the heap.


Last time I said this, I seem to remember Jim or Earnest telling me this was no longer true. In Java 6, apparently, the JVM is smart enough to realise some objects are used only locally within a particular method, and sticks them on the stack.

Even assuming this is true, it's a JVM internal implementation detail, of academic interest only. From the point of view of the Java programmer, all objects still behave as if they were on the heap.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!