Stack memory usually stores local variables, method calls, one over the other ..
Stack is always busy in arranging the data and popping it out after the method is executed.
stack memory stores the primitive datatype like int, double, etc.,
stack only stores the address (in other words points to the data in heap),
say when you create a new object from your class A from a new program,
A X(object ) = new A;
creating 'new' object uses both stack and heap ,,
whereas stack will store the address of the object in the heap (.. just an address..)
the real data will be stored on the heap.
when we create another object from the class A,
A Y = new A;
and when we assign,
Y=X;
what will happen is, Y will just store the address of the variables used in the heap,
so,
passing message to the objects X and Y makes no difference .
when you pass message to your object,
x.move();
this method move(), is allocated in stack and it will just refer the heap memory with its address..
after the execution of move(), stack pops it out(that is why i said it is very active and busy)
Garbage collection is the process that java does to reclaim the memory when it is no longer used ....