Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Island of isolation

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When the code reaches here, which 3 objects are GC?At line 6,i4.i refers to Island object and i2.i refers to island object,i3.i refers to island object.three objects(new Islands()) are already having object references(i2.i,i3.i,i4.i) refers to that.i2,i3,i4 are not objects.Those are object references.Then which three objects are eligible for GC here and how?Please help me.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shiva,

Then which three objects are eligible for GC here and how?


I think:

I mean the three new Island-objects, not the references.
And I don't think, that this is an example of island of isolation. i2,3,4 are all nulled so all of their member variables (i) don't have an object which they could reference.
And no live thread can access these i2,3,4. So the three above are eligible for garbage collection.

Or am I wrong?


Yours,
Bu.
 
wise owen
Ranch Hand
Posts: 2023
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wise,

thank you for correcting me by providing the link.

I was wrong, this IS an example of an island of isolation.
Your nulling the "outer" islands. The member islands form an island of isolation, so GC can finalize the outer islands even though, there are references to them, but these are isolated.



I extended the code a bit, so it prints something:




Prints out: (VM dependent)
after line 6before calling System.gc
after calling gc
"when the code reaches here"before calling System.gc
Island 4 finalized
Island 3 finalized
Island 2 finalized
after calling gc
ready






Yours,

Bu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic