The temp variable is out of scope for YOU, but the variable lives in a stack that is related to the JVM Frame. There is one Frame per Method, so there is a reference to the last object until the end of the Method. ------------------ Cindy Glass Sun Certified Programmer for the Java� 2 Platform Co-author of Java 2 Certification Passport
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: May 11, 2001
Thank you That answers my question... But, what do you mean my stack?
Joined: Sep 29, 2000
Objects live on the heap (an area that the OS assigns to the jvm for general use). Variables live in a Stack kept separately from the general heap. It is a vector-like storage place that is Last-in-First-Out that the JVM pushes values onto and pops them off. Of course a JAVA stack IS a Vector - but the JVM may not be written in Java. Form the JVM Specification
3.5.2 Java Virtual Machine Stacks Each Java virtual machine thread has a private Java virtual machine stack, created at the same time as the thread.3 A Java virtual machine stack stores frames (�3.6). A Java virtual machine stack is analogous to the stack of a conventional language such as C: it holds local variables and partial results, and plays a part in method invocation and return. Because the Java virtual machine stack is never manipulated directly except to push and pop frames, frames may be heap allocated. The memory for a Java virtual machine stack does not need to be contiguous. The Java virtual machine specification permits Java virtual machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation. If the Java virtual machine stacks are of a fixed size, the size of each Java virtual machine stack may be chosen independently when that stack is created. A Java virtual machine implementation may provide the programmer or the user control over the initial size of Java virtual machine stacks, as well as, in the case of dynamically expanding or contracting Java virtual machine stacks, control over the maximum and minimum sizes.4 The following exceptional conditions are associated with Java virtual machine stacks:
If the computation in a thread requires a larger Java virtual machine stack than is permitted, the Java virtual machine throws a StackOverflowError. If Java virtual machine stacks can be dynamically expanded, and expansion is attempted but insufficient memory can be made available to effect the expansion, or if insufficient memory can be made available to create the initial Java virtual machine stack for a new thread, the Java virtual machine throws an OutOfMemoryError