Search code examples
javamemory-managementdiagram

java and memory layout


Hey guys, I'm reviewing some questions but I can't really figure it out, i looked through the text book but i'm not sure where i can find answer...

I know it would be quite hard to do memory diagrams w/o pictures but please bear with me.

interface Lovable
   public void love();

class Foo implements Lovable
   public void love();
      // something
   public int val()
      // return something1

public class Love
   public static void main(String args [])
      Foo foo = new Foo()
      foo.love()
      foo.love()
      int bar = =foo.val()
      System.out.print(v)

Now, I see that foo is declared with new, so I know actual Foo class information is stored in heap and there's a frame?pointer? that points to that memory space in heap on top of the stack (before foo calls any methods). so then what about the interface? would that be stored in the heap too?

so on the bottom of the stack would be the class Love(also contains int bar), a pointer that points to Foo foo in heap, a frame for foo.love(), another frame foo.love(), a fram for foo.val(), a framee for print?

Am i getting the idea ? or am i really really far off? If you know any where I can get more information, please let me know. I appreciate any input..


Solution

  • Generally, are objects are stored on the heap managed by the garbage collector.

    Only the latest release of Java 6 has escape analysis to store objects on the stack if they do not escape.

    Class information is store in the perm space.