Vince Tan wrote:Question 1:
On page 166, it's stated that local variables live on the stack instead of the heap. So, wouldn't the w1 and w2 live on the stack and won't be eligible for GC since it's not even in the heap?
Vince Tan wrote:Question 2:
The string literal within the print statement in the go() method would still contain reference to it from the String Literal Pool so it would not be eligible for GC, is this right? Just to confirm it would only create one object in the heap?
Vince Tan wrote:Question 3:
When the new Wind(3) object gets created in the main() method, does it create one object (the Wind) or does it creates 2 (the Wind and the int id within the object - unless primitive types are not considered an object? )?
Vince Tan wrote:Question 4:
I guess this is related to Q3, when an instance of a class gets created (an object with say 2 objects or classes and 1 primitive type), how many objects get created in the heap? I assume it should be just one as the containing Objects and primitive types should be part of this main object?
Roel De Nijs wrote:
Given this code snippet:How many (and which) objects will be created if you call new Kitchen(5, 32); (in a main method for example)?
Hope it helps!
Kind regards,
Roel
Roel De Nijs wrote:
Mateus Brigido wrote:One Kitchen object
Five Chairs objects
One Table object
Is this right?
Close, but no cigar!![]()
Mateus Brigido wrote:
Roel De Nijs wrote:
Mateus Brigido wrote:One Kitchen object
Five Chairs objects
One Table object
Is this right?
Close, but no cigar!![]()
One ArrayList Object, just forgot that one![]()
Vince Tan wrote:I understand that " " will be in the heap with a referenced from the String Literal Pool. However, when the entire string gets generated as in "1 2" will this string gets stored in the heap the same way as the " " ?
Vince Tan wrote:Will the above creates 2 objects in the heap?
String object 1 -> " "
String object 2 -> "1 2"
Vince Tan wrote:1/ " " <-- is this considered a string literal and will be referenced by the pool hence NOT eligible by GC?
2/ "1 " <-- generated on the fly hence will be in the heap with no reference from the pool
3/ "1 2" <-- generated on the fly hence will be in the heap with no reference from the pool
K&B7 wrote:Note: Due to the vagaries of the String constant pool, the exam focuses its garbage collection questions on non-String objects, and so our garbage collection discussions apply to only non-String objects too.
Consider Paul's rocket mass heater. |