This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
hi Edisandro you are correct only object created in m method eligible for gc
Joined: Mar 03, 2006
here , method is returning object so how that object is eligible for garbage colection ? i read in k&b at page 434(Reassining a reference variable) object return by method is not eligible for garbage collection.
so i think , there is no object eligible for garbage collection. is there anyone who think so ?
No amisha u r wrong... yeah ur partially correct...method is returning the object reference and is set to c2 ..so at that time object created in m1 method is not eligible for garbage...Then have a look at this code..
C c3=new C(); c2=c3; //6 so a new object referenced by c3 is created..and then c2 is made to refer to this new created object....
So the object previously refered by c2 become eligible for gabrage collection...