Answer wrote:C is correct. Only one Cardboard object (c1) is eligible, but it has an associated Short wrapper object that is also eligible.
If c1 is null and its eligible, why c3 isnt also eligible? because is also null.
Roel De Nijs wrote:And now a little pop-quiz: what if line 3 was changed to short story = 200;? How many objects will there be created now? Still 4?
Javier Giron wrote:
Roel De Nijs wrote:And now a little pop-quiz: what if line 3 was changed to short story = 200;? How many objects will there be created now? Still 4?
Just two objects, the CardBoard ones, because the short variable isnt a object anymore is a primitive variable, right?
Javier Giron wrote:And also i dont understand the next. Why c2 isnt null at the end of the code? Because, as i understand, the Cardboard cb in the funtion go() is pointing to the same object as c2. So when the code says "cb = null;" isnt making c2 = null? (I know this is incorrect because i executed the code and isnt working like that, but i cant understand why)
Sharmili Rameshbabu wrote:I have few doubts regarding this topic. Can you please address them.
Sharmili Rameshbabu wrote:1. If the value of the instance variable story was in the range of -128 to 127, then there are no objects created for it. Right?
Sharmili Rameshbabu wrote:2. if line 1 is added in the below code , then object referred by story is not eligible for garbage collection. Right?
Sharmili Rameshbabu wrote:3. If line 1 is modified as short s=c1.story; does the behaviour is same as the previous one?
Sharmili Rameshbabu wrote:4. If a class has a static member variable, they are never eligible for garbage collection till the program terminates. Right? As in this example
Roel De Nijs wrote:
Sharmili Rameshbabu wrote:1. If the value of the instance variable story was in the range of -128 to 127, then there are no objects created for it. Right?
You are referring to the cached values. So when the 1st instance of CardBoard is created a new instance of Short (with value 200) will be created. On every next instantiation of CardBoard, this instance will be used (and thus no others will be created).
Sharmili Rameshbabu wrote:(with value 200)??? I meant to ask if it was say Short story=1; then there are no objects created in heap, since they are created in cache and referred by all the instances of the CardBoard, So answer to the question would be just 1 object(c1) eligible of garbage collection. Correct?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |