• 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

Memory Managment

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic