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(): " +
rt.freeMemory());
System.runFinalization();
System.gc();
System.out.println(" Free Memory after call to gc(): " +
rt.freeMemory());

}
}

class GC1 {

String str;
int id;

GC1(int i) {
this.str = new String("abcdefghijklmnopqrstuvwxyz");
this.id = 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. 1==how can we use vb.net web service data in JSF?<
View Tutorial          By: kumaraswamy at 2009-01-06 23:56:53

2. it is very nice example of overloading when i read
View Tutorial          By: narendra saini at 2012-04-20 04:03:56

3. i always encounter a problem every time we discuss
View Tutorial          By: sukira 18 at 2009-08-29 03:25:23

4. error is main fuuction declaration
void mai

View Tutorial          By: T.M.Prakash.MCA. at 2012-09-20 12:26:52

5. this tutorial example of inheritence is taken from
View Tutorial          By: vinod kumar gaur at 2011-07-17 23:18:00

6. Thank you very much. Very useful. You are the best
View Tutorial          By: lin at 2011-01-19 00:09:35

7. very nice content
View Tutorial          By: jagadeesh at 2012-04-25 06:24:03

8. Great!
Thnks for your help..

View Tutorial          By: ramu at 2011-06-18 07:56:56

9. What if I wanted POST instead of GET?
View Tutorial          By: Otto at 2011-06-12 15:38:50

10. good explanation ,it is very very understandable
View Tutorial          By: chaitanya at 2011-10-27 16:21:55