• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Memory Managment

 
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...
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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.
 
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!