Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Dan's question

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Which object is not eligible for garbage collection after method m1 returns?
My understanding inside the method m1()
i1,i2,i3,i4 refers to each I() object,can anyone please explain i1.other(i3).
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each instance of I has a variable "other" that holds a reference to another
instance of I.

So


Assigns the object reference i3 to i1's instance variable other. There by giving i1 a reference to the object currently referenced by i3.



Lets call the 4 objects created in these 2 lines O1, O2, O3, O4.

So at the end (before returning) of m1()

i1 is a reference to O1
i2 is a reference to O2
i3 is a reference to O3
i4 is a reference to O4

O1.other is a reference to O3
O3.other is a reference to O2
O2.other is a reference to O1

04.other is a reference to O4.

But after returning from m1() no live thread has a reference to O1, O2, O3, or O4 so I would think they are all eligible for garbage collection. You don't keep a reference to the J object created, so its eligible also. If the program didn't terminate after the call to m1() the array object reference by args wouldn't be eligible for garbage collection.

Or did a somehow miss something?
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic