aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes garbage collection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "garbage collection?" Watch "garbage collection?" New topic
Author

garbage collection?

raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
import java.awt.*;
public class test
{
TextField tf;
public void initComp()
{
Panel p = new Panel();
tf = new TextField();
p.add(tf);
}
public static void main(String args[])
{
Frame f = new Frame("test");
f.setVisible(true);
f.pack();
test t = new test();
f.add(test.initComp());
}
}
is Panel p in initComp() method eligible for garbage collection by the time the method exits?
raymond
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
Hi raymond
ur prog will not compile ...
AW Panel p in initComp() method IS eligible for garbage collection by the time the method exits AS all local variable/refrence are elegible to be collected by garbage as stack has to be cleaned.
HTH
CMIW


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
import java.awt.*;
public class garbage
{
TextField tf;
Panel mainPanel = new Panel();
public void initComp()
{
Panel p = new Panel();
tf = new TextField();
p.add(tf);
mainPanel.add(p);
}
public static void main(String args[])
{
Frame f = new Frame("test");
f.setVisible(true);
f.pack();
garbage t = new garbage();
t.initComp();
f.add(t.mainPanel);
}
}
sorry i put the wrong code. here's my new code and my question is: Is Panel p in initComp() method eligible for garbage collection as the method terminates?(the Panel p still holds the TextField f);
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
no it is not, but not because the Panel p still holds the TextField f, but because mainpanel holds a reference to p and mainpanel is an instance member of class garbage...


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
wood burning stoves
 
subject: garbage collection?