Here is the Java code written.
- class Demo {
- public static void main(String s[]) throws Exception {
- Runtime rs = Runtime.getRuntime();
- System.out.println("Free memory in jvm before Garbage Collection = " + rs.freeMemory());
- rs.gc();
- System.out.println("Free memory in jvm after Garbage Collection = " + rs.freeMemory());
- }
- }
Thank you, keep learning and sharing.