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. @Sonal, as long as the image is stored in a server
View Tutorial          By: alex at 2012-11-07 07:25:40

2. I had downloaded all 5 the file
but i need

View Tutorial          By: Dhananjay at 2009-12-09 10:20:30

3. Hello, I have a problem
I cant understand s

View Tutorial          By: henry at 2012-01-10 07:53:05

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

5. i need to code for sparse matrix in java. please
View Tutorial          By: sudhi at 2012-10-01 09:34:57

6. Hello,
I want to send an mulitple sms using

View Tutorial          By: Fionna at 2009-07-10 01:02:11

7. Easy to understand.good work
View Tutorial          By: Deepika at 2013-12-13 09:33:55

8. i like java but java many program are confused i a
View Tutorial          By: savaliya hardik at 2012-09-11 03:30:10

9. the superb way of making new concepts learn with e
View Tutorial          By: Ghulam MOhmad at 2008-09-18 23:43:42

10. Nice basics. Very helpful
View Tutorial          By: Gorav at 2011-11-11 12:46:28