• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object eligable to GC

 
wei liu
Ranch Hand
Posts: 35
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone,

Can someone help me to understand following question

in Kathy sierra and bert bates book Page 277 self test question 1


why is the CardBoard Object c3 is not eligiable to GC and why Short wrapper object is eliable?

Thanks.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About the Short:
c1 is no longer accessible and it contains a Short object, so that object is also eligible for GC.

About c3:
Remember that c3 is only a reference. c1 and c2 were referencing an Object but there was no object for c3. Therefor there is no object to be GC'ed. If c3 was referencing to an object then it would also be eligible.

Next time post the question so that others that don't have the book could help you.
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wei not everyone has that book and even if they have the book, they might not have the book with them all the time. In the future you can get better response if you provide the question with which you are confused. This provides an opportunity for everyone to help you and also helps them to understand the topic and increase their own knowledge...
 
Michelle Chang
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Along the same line, my question for Q1 in chapter 3 is that if the local variable cb is also eligible for GC? why or why not? Thanks.

Below is the question again:


When // doStuff is reached, how many objects are eligible for GC?
A. 0
B. 1
C. 2
D. Compilation fails
E. It is not possible to know
F. An exception is thrown at runtime
Answer:
✓ C is correct. Only one CardBoard object (c1) is eligible, but it has an associated Short
wrapper object that is also eligible.
A, B, D, E, and F are incorrect based on the above. (Objective 7.4)
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4122
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shifong Chang wrote: my question for Q1 in chapter 3 is that if the local variable cb is also eligible for GC? why or why not?

Not variables are eligible for the GC. Only the objects, which are *not* referred by any variable, are eligible for the GC. The object passed to the go(~) method (line-11) is already referenced by'c2' - hence, it is not eligible for the GC.
 
KrishnaPrasad raghavan
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So c1 and c3 are eligible for GC. Am i correct here?.

The cb within the object is not eligible for gc even though it is made to refer to null.



The cb here won't be eligible for GC.. is it ?.
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4122
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only 'c1' and 'story' ('story' of 'c1') is eligible for the GC.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic