aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Garbage Collection" Watch "Garbage Collection" New topic
Author

Garbage Collection

Akash Bhatt
Greenhorn

Joined: Jul 26, 2005
Posts: 25
public class XYZ{
ABC obj=new ABC();
mth1{
System.out.println(obj);
}

}
public class C{
public static void main{
XYZ obj1= new XYZ();
obj1.mth1();
}
}

in Class C when main method ends the object for XYZ is eligible for collection by the GC. But happens to the reference 'obj' created in XYZ..??? Is IT too eligible for collection..??


...ToucH SkieS
AKASH
SCJP 1.4 86%
SCWCD 1.4 82%
Ankur Sharma
Ranch Hand

Joined: Dec 27, 2005
Posts: 1234
Originally posted by Akash Bhatt:
public class XYZ{
ABC obj=new ABC();
mth1{
System.out.println(obj);
}

}
public class C{
public static void main{
XYZ obj1= new XYZ();
obj1.mth1();
}
}

in Class C when main method ends the object for XYZ is eligible for collection by the GC. But happens to the reference 'obj' created in XYZ..??? Is IT too eligible for collection..??


If main threads ends up then all objects are eligible for Garbage Collection.

It's quite obvious.

Pls correct me If I am wrong.


The Best way to predict your future is to create it
Ankur Sharma
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Yes, the object of type ABC referenced by obj is eligible for garbage collection. You effectively have two linked objects with no active thread referencing either of them. Imagine a red kite tied to a blue kite. If you are holding the string to the blue kite and you let go, both kites will be blown away.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Garbage Collection
 
Similar Threads
Casting , why so? Any help?
Casting , why so? Any help?...More....
garbage collection
GC
Question about garbage collection