OCPJP 6, OCMJD
Stephan van Hulst wrote
Objects (usually, but not always) live on the heap
ayush raj wrote:Reference variable live on stack and not on heap.
Please site an example for this .
Stephan van Hulst wrote : objects that are created in a method, and never wander outside of that method (by passing them as arguments to other methods, or by assigning them to a field) are very likely to be stored on the stack
ayush raj wrote:Please correct me if i am wrong ..
Joanne
Joanne Neal wrote:
ayush raj wrote:Please correct me if i am wrong ..
Do a search for escape analysis which was implemented in later updates of Java 6 and in Java 7.
ayush raj wrote:Cant understand what you guys are talking about escape sequence !!
Joanne
Stephan van Hulst wrote:There is no rule. It's a trick. It's a small optimization that a particular compiler might employ to reduce the strain on the garbage collector.
Escape analysis refers to a technique where the compiler inspects a method to figure out in what places a method call may return, and what some possible states of the program are when the method returns. This has various useful applications.
One of these applications is that when the new keyword is used to create an object, the object may be stored on the stack, because it's only used temporarily, and it's much easier to clean up the stack than the heap.
ayush raj wrote:How should we answer such questions on the exam then , if its asked whether its true/false : an object can live on stack as well as on heap ?
Henry Wong wrote:
ayush raj wrote:How should we answer such questions on the exam then , if its asked whether its true/false : an object can live on stack as well as on heap ?
I think that the correct answer is to answer it the way that you were taught. After all, the goal is to pass the test... .... just remember to have an open mind, and understand that tests (and knowledge) can be outdated (and you are merely giving the "correct" (but outdated) answer to an outdated test).
Henry
OCPJP 6, OCMJD
Instance variables and objects live on the heap.
Local variables live on the stack
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|