-
Junior Member
Need more information on finalize method.
This is the definition i got:
Before an object is garbage collected, the runtime system calls its finalize() method. Your class can provide for its finalization simply by defining and implementing a method in your class named finalize().
public class garbagecollector {
public static void main(String args[])
{
System.out.println("a");
System.out.println("b");
}
protected void finalize() throws Throwable {
System.out.println("GC");
}
}
ideally this should get the output
abGC
but i am getting only
ab
Why is this so?. and why the finalize() is not getting called?.
Any help regarding this?. I am really confused about it.
-
Junior Member
Re: Need more information on finalize method.
Hello TigerElango,
We can only suggest the Garbagecollector ,but we can't force it ,rest it will does with its default behaviour.....
we can suggest it like the code given below....
public class Garbagecollector {
public static void main(String args[])
{
System.out.println("a");
System.out.println("b");
Garbagecollector garbagecollector = new Garbagecollector();
try {
garbagecollector.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
}
protected void finalize() throws Throwable {
System.out.println("GC");
}
}
-
Junior Member
Re: Need more information on finalize method.
trycatch,
Is there any Garbagecollector class in java. In jdk1.5.0 api there is no such class defined.
Can u explain bit ellaborate on this.
Regards,
Elangovan R.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules