Originally posted by Edisandro Bessa:
In summary, reference variables are always created on the heap, regardless whether or not they are inside a method.
Sorry, but this is wrong. All objects are created on the heap; this includes, of course, the contents of all objects (their member variables). But local variables, regardless of their type, are always on the stack. The object a local reference variable refers to is, like all objects, on the heap; but local variables of every type, reference or primitive, are on the stack.
As to your correction of someone's correction: that's really not right either. When a variable goes out of scope, it's gone. It doesn't matter what kind of variable it is. This is quite apart from the lifetime of any object a variable might have referred to. As soon as an object is unreachable, it's gone. The JVM may grind it to a pulp instantly, or it may never collect it. But just the same, it's gone to your program, and that's perfectly determinate.