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

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. i totally disagree with Gerardo Saldív
View Tutorial          By: Shivesh at 2009-09-24 23:46:42

2. How to connect a webpage(which I have created for
View Tutorial          By: sam at 2012-01-24 10:10:52

3. hi thanks for your tutorial, but I can`t run your
View Tutorial          By: yashar at 2015-05-29 18:57:30

4. I want to know more about Java Garbage collection,
View Tutorial          By: Prosenjit Kundu at 2010-05-08 09:42:40

5. Hi..
How can i read .mp3 files from memory

View Tutorial          By: satyanarayana at 2010-03-29 11:14:27

6. concept of static keyword is beautifully explained
View Tutorial          By: jaideep aswal at 2012-04-14 07:21:56

7. hi...
how can i get this 5 files...of java.

View Tutorial          By: loveu at 2010-09-19 12:04:10

8. The following line in the code

View Tutorial          By: Carlos at 2009-11-18 14:34:51

9. good work done.
View Tutorial          By: Nitin at 2009-08-29 10:51:41

10. To determine current location in a file:

View Tutorial          By: Terry at 2009-09-27 13:15:56