Sample code to manually call Garbage collector
package funds;
class Student
{
int num=10;
String name="laxman";
}
public class GCDemo {
public static void main(String arg[])
{
//nullifying reference varable
Student s1=new Student();
s1=null; // destructed by GarbageCollector
// Reassigning the reference variable
Student s2=new Student();
Student s3=new Student();
s1=s2; // s1 pointed object destructed by GarbageCollector
}
}
0 comments:
Post a Comment