John Ren
Posts: 2
Nickname: javaren
Registered: Mar, 2002
|
|
Re: Where does object live?
|
Posted: Mar 7, 2002 6:41 PM
|
|
Firstly we thank you very much.
We are students in China. We are reading 'Thinking in Java 2nd Edition'. Possibly because of the difference of language, we meet the following question:
In section 'Where storage lives' in Chapter 2, about heap we get the information "This is a general-purpose pool of memory (also in the RAM area) where all Java objects live. " In section 'Special case: primitive types' in the same chapter, in the first paragraph there is an information "That is, instead of creating the variable using new, an "automatic" variable is created that is not a reference. The variable holds the value, and it's placed on the stack so it's much more efficient. "
The question is that if a object has only one data member(field) of a primitive type and the object lives on the heap, where is that field placed? According to the 2nd information, it should be placed on stack, but the object is living on the heap.
Now you've given us a deep-level and clear answer, which of course dismissed the question above. So let us say appreciation to you again.
|
|