• Post Reply Bookmark Topic Watch Topic
  • New Topic

garbage collector  RSS feed

 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




After the comment line how many objects are eligible for garbage collecton?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many do you think are eligible and why.
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As there are totally 6 reference in the heap and three objects has assigned null and 'a2' does not assigned null with the help of a2 we can access (b1 and b2 in Alpha class)my answer is 3 objects(a1,b1,,b2)in main method.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bairava surya wrote:As there are totally 6 reference in the heap and three objects has assigned null


I only see four objects instantiated. Can you show us in code, where these six objects where created? Or are you confusing objects and references?

Henry
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry am telling the total contents in the heap is 6.
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone help me with the problem?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags to your post. it's easier to read, and we can all now refer to line numbers.

I see Beta objects created on lines 13 and 14, and two Alpha objects created on 15 and 16. Regardless of what objects become available for GC, where do you see two additional objects created that might be?
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this question has been obtained from study guide they printed answer as only one object eligible explain me what about other objects!
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bairava surya wrote:can anyone help me with the problem?


It is probably a good idea to separate the idea of objects and references. Once you do that, you will be able to connect the references to the objects.

As mentioned, there are four objects. Mark them on paper (in a diagram), and don't use the references to mark them, because that can change.

There are actually seven references. Four are local variables. Two are instance variables. And one is a static variable. You also have to remember that in the case of the static variable, you don't actually need an instance to access it.


So, is that enough ideas for you to draw out what is reachable or not?

Henry
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cany anyone tel me the exact reason how one object is eligible for garabage collection and what about remaining objects?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bairava surya wrote:tel me the exact reason how one object is eligible for garabage collection and what about remaining objects?

bairava, you are asking the impossible (which seems to be a trend).

Most gc's these days are almost certainly heuristic-based algorithms based on "current statistics", so even if you knew what it was based on, you'd be hard-pressed to predict how it's going to work.

And I would appreciate it if you "asked" questions rather than "demanding" answers. This is now the third time I've posted about this, and frankly, I'm getting tired of it. If you don't feel willing to conform to our guidelines, then find another site.

If I see any further violations of the HowToAskQuestionsOnJavaRanch guidelines, I shall ask my colleagues to suspend your account.

Winston
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As a side note, in my opinion, in terms of difficulty, this seems to be one of the easier GC reachability questions encountered. I would recommend that the OP, use some paper and a pencil, and work it though (as previously recommended) -- as you are going to be encountering more difficult cases later.

Henry
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!