Comment on Tutorial - Garbage collection and Finalize() method By aathishankaran

Comment Added by : sreekar

Comment Added at : 2010-05-08 07:58:09

Comment on Tutorial : Garbage collection and Finalize() method By aathishankaran
/** Example shows garbage collector in action
Note that the finalize() method of object GC1
runs without being specifically called and that
the id's of garbage collected objects are not
always sequential.

class TestGC {

public static void main(String[] args) {

Runtime rt = Runtime.getRuntime();

System.out.println("Available Free Memory: " + rt.freeMemory());

for(int i=0; i<10000; i++ ) {
GC1 x = new GC1(i);

System.out.println("Free Memory before call to gc(): " +
System.out.println(" Free Memory after call to gc(): " +


class GC1 {

String str;
int id;

GC1(int i) {
this.str = new String("abcdefghijklmnopqrstuvwxyz"); = i;

protected void finalize() {
System.out.println("GC1 object " + id + " has been finalized.");


View Tutorial

Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Thanks Thanks Thanks.....for you
But how

View Tutorial          By: jihad at 2009-02-15 04:48:53

2. it's really Nice Clock
View Tutorial          By: Mido at 2007-09-09 08:45:49

3. When I use this code it puts everything I append o
View Tutorial          By: Amber at 2012-06-18 15:33:22

4. this is the one of the best site to search java pr
View Tutorial          By: gautam gorai at 2009-01-13 06:44:15

5. that was gud example to explain abstract. i have d
View Tutorial          By: zishan at 2010-05-20 00:21:46

6. hi..dud.......
please help me in my proj

View Tutorial          By: amar usakoyal at 2010-05-25 03:31:16

7. Good example.

Leslie V

View Tutorial          By: Leslie V at 2009-10-14 00:47:06

8. Very nice and easy to understand, keep it up !!
View Tutorial          By: claudiu at 2010-02-07 06:12:30

9. Sir your example is god
but i am surprisin

View Tutorial          By: Ata Ul Nasar at 2011-06-05 16:23:09

10. short and simple program

View Tutorial          By: sourabh agrawal at 2012-10-16 04:55:27