From 7fcccd23a601055f9b5f7882f7f7c238290f691d Mon Sep 17 00:00:00 2001 From: deecode15800 <72188292+deecode15800@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:22:07 +0530 Subject: [PATCH 1/2] GarbageCollect.java please merge , for Hactoberfest2023 --- GarbageCollect.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 GarbageCollect.java 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 From be23a5658c8417fdbd3cb0ad6cec00f510c16212 Mon Sep 17 00:00:00 2001 From: deecode15800 <72188292+deecode15800@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:24:17 +0530 Subject: [PATCH 2/2] GarbageCollect.java Hactoberfest2023 --- Programs/GarbageCollect.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Programs/GarbageCollect.java 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