Say we have a method named method1 that our program calls at some point.
Then the method creates an object and uses it. The lassie variable is allocated on the stack and it references (points to) an object on the heap.
Then the method exits its block. The JVM clears the stack so that there's no longer any references to the object.
At some later time, the garbage collector kicks in, scans the stack and the heap - since the object has no references, the GC deletes it.
public void method1() { Dog lassie = new Dog(); lassie.eat(); }