Topic 10 - Java Memory Management Flashcards
Call stack / runtime stack does what and contains what?
Used for method information while the method is being executed. Contains: - formal parameters - local variables - return value - where the method should return to
What is Heap used for?
Static information (interfaces and classes). Instance information (objects).
What happens when an object is created by the New keyword?
1) Reference variable has memory allocated to it in the call stack
2) The object is created using memory in the heap
What is being used when a method is being run?
Memory space in the call stack / runtime stack.
Explain specifically what happens when a method is used / invoked?
A call frame (activation record) is created and “pushed” onto the runtime stack.
What does the Static space in the heap contain?
One copy of the interface and class along with their static variables and methods
What does the object space in the heap contain?
1) Value of instance variables
2) Type of object
What happens to objects after a method returns?
Object stays on the heap. Even if there is no longer a variable referencing it. Java has automatic garbage collection.