The heap stores all objects, including all arrays and all class variables.
The stack stores all local variables, including parameters.
When a method is called, Java creates a stack frame (aka activation record); stores the parameters and local variables.
Stack of tack frame.
Garbage collection only performs on heap.
When a method finishes, its stack frame is erased.
Method "Thread.dumpStack()": Prints a stack trace of the current thread to the standard error stream. This method is used only for debugging.
Parameter Passing
Java passes all parameters by value: copied.
When parameter is a reference, the reference is copied, but the object is shared.
No comments:
Post a Comment