Discussion :: Garbage Collections - General Questions (Q.No.4)
|Sr Dev said: (Jan 9, 2012)|
|Instance of Demo which got created at line 12 is eligible for garbage collection after "takeDemo" method because the scope of the reference become out. So please review it and ask like "When will the the instance created at line 6 is eligible for Garbage Collection"|
|Bishoy said: (Oct 1, 2013)|
The question is confusing that way, instead of saying "the Demo object" in the question, you have to define which object of the two you mean.
|Rajiv said: (Dec 27, 2013)|
|It seems that the static modifier must be used with private Demo d.
So that we treat it as class variable and then the explanation will be ok for this question.
|Bhs said: (Apr 21, 2014)|
|Is it just me or someone else too feels option B and C are technically same?|
|Atul said: (Jun 29, 2014)|
|The object created before calling takeDemo method will be eligible because in first statement of the method called, demo=null; is set, and in java objects always gets passed by reference so it will get set to null, and object will be eligible for GC.|
|Flashy said: (Nov 12, 2016)|
|How can you define a new Demo() when there is no Demo class?|
|Uwe said: (Mar 9, 2017)|
|I too have the same doubt @Flashy.|
|Saurabh Gupta said: (Aug 6, 2017)|
You just said exactly what was in my mind. And @Flashy and @Uwe consider the class name as Demo instead of Test.
As Atul said demo = null is the line which makes the object available for GC and this option is not given in the question.
|Surendra J said: (Nov 20, 2017)|
|This program show runtime error, then how is possible By a process of elimination?|
|Ken said: (Feb 17, 2018)|
|As mentioned by "Sir Dev" a bit of clarification on the wording, could you consider changing: "When is the Demo object eligible for garbage collection?" to "When is Test's Demo instance eligible for garbage collection?" OR "When is the Demo object 'd' eligible for garbage collection?" as the Demo object created in takeDemo could be confused with the instance variable for which the question assumes.|
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.