diff --git a/GarbageCollect.java b/GarbageCollect.java new file mode 100644 index 0000000..0037cd0 --- /dev/null +++ b/GarbageCollect.java @@ -0,0 +1,20 @@ +class Sample{ + Sample(){ + System.out.println("Object created"); + } + + protected void finalize(){ + System.out.println("Object destroyed"); + } +} +public class GarbageCollect { + public static void main(String[] args) { + Sample obj=new Sample(); + obj=null; + Sample one=new Sample(); + Sample two=new Sample(); + one=two; + + System.gc(); + } +} \ No newline at end of file diff --git a/Programs/GarbageCollect.java b/Programs/GarbageCollect.java new file mode 100644 index 0000000..0037cd0 --- /dev/null +++ b/Programs/GarbageCollect.java @@ -0,0 +1,20 @@ +class Sample{ + Sample(){ + System.out.println("Object created"); + } + + protected void finalize(){ + System.out.println("Object destroyed"); + } +} +public class GarbageCollect { + public static void main(String[] args) { + Sample obj=new Sample(); + obj=null; + Sample one=new Sample(); + Sample two=new Sample(); + one=two; + + System.gc(); + } +} \ No newline at end of file