• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 3 Self Test Question - 1 "Garbage Collection"

 
Brian Brumpton
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay,

I've taken this self test twice now and the first time I marked the question wrong, the second time I marked it correctly (but for the wrong reasons). I take that to mean I'm not quite grasping the concept.

The questions states:

GivenWhen // do Stuff is reached, how many objects are eligible for garbage collection?

A. 0
B. 1
C. 2
D. Compilation fails
E. It is not possible to know
F. An exception is thrown at runtime

I tried diagraming it as suggested here

Am I correct in thinking that an object is not instantiated for c3? And in that case a total of four objects are created 2 x CardBoard and 2 x Short?
Diagram.png
[Thumbnail for Diagram.png]
Diagram
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread covers the same question and has some great explanations about different scenarios. Does it answer/clear your question/doubts?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Brumpton wrote:Am I correct in thinking that an object is not instantiated for c3? And in that case a total of four objects are created 2 x CardBoard and 2 x Short?

Yes, you are correct! A detailed explanation you'll find in the thread I mentioned in my previous post.
 
Brian Brumpton
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it answer/clear your question/doubts?


Yes. That post made good sense to me, except the last part about cache (not sure I need to know that for the exam but I'll give it another read). And you've reminded me once before about paying attention to the keyword "new" being required to instantiate objects (with a few exceptions, wrapper classes being one of them). I promise, you'll only have to remind one more time before I get it through my thick head.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Brumpton wrote:Yes. That post made good sense to me, except the last part about cache (not sure I need to know that for the exam but I'll give it another read).

Yes, you need to know the caching of wrapper class objects. You'll find a great explanation with tons of examples in this thread.

If you have read (and understood) that thread, you should be able to explain why the correct answer is different if you replace line 2 with this line of code:

Brian Brumpton wrote:And you've reminded me once before about paying attention to the keyword "new" being required to instantiate objects (with a few exceptions, wrapper classes being one of them).

Correct! And String being the other one
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic