• Post Reply Bookmark Topic Watch Topic
  • New Topic

Garbage Collection  RSS feed

 
Greenhorn
Posts: 18
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many objects will be available for garbage collection when the execution reaches at line16.?
I am confused!
Given:
 
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Akash.

I reformatted your code and took out the color (very hard to read, I thought). Please useCodeTags <- click here, and indent your code. We can do a better job of helping you if you do.
 
Marshal
Posts: 56610
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many do you think? Get a pencil and paper and write down all the objects you can see. Draw a little box for each object and mark that when it becomes unreachable. Check carefully that you don't hae the same object twice. I think you can ignore the args array.

Remember this sort of question is only of use for certification exams, and once you have passed you will never looks at such a question again.
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Remember this sort of question is only of use for certification exams, and once you have passed you will never looks at such a question again.


So true. I looked into working for Raytheon, recently (mostly because they opened up a big campus nearby). Their "work for us" Web page rather explicitly states that they do not care at all about certifications. I think questions that address subjects like this on exams may be part of the reason.
 
Greenhorn
Posts: 27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am guessing you are preparing for OCAJP certificate right?
About the answer this is called island of isolation. Firstly you look that reference a2 is not set to null so it means this object is not eligible for garbage collection(the same for a2.b2). Secondly you should look carefullY TO STATIC VARIABLES. there is still a reference to a2.b1. So for garbage collection is available only one object which is a1 reference .

Hope it helps
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!