About garbage collection and finalize () problem

Category: Java SE
 
sihai90
2012-02-24 11:43:08

Sponsored Links
Garbage collection is how it is, in the end how to use ah? I am thinking in java
looked a long time did not understand the above, there is finalize () usage
This is what I wrote a related classes, why can not enforce finalize ()
public class Tank {
private boolean b = false;
public Tank () {
System.out.println (" Bryant ");
}
void full () {
b = false;
}
void empty () {
b = true;
}
public void finalize () {
if (b)
; System.out.println ("Empty");
}
public static void main (String [] args) {
Tank tank = new Tank ();
System. gc ();
}
}
there is a problem is how Results posted?

Sponsored Links

wo471348615
2012-02-25 12:08:30
only suggested recycling only, not mandatory
10 minutes even, and does not bear mentioning
tjzyj2009
2012-02-25 12:42:25
declare a class is not generally recommended finalize method ~ ~
zjc12
2012-02-25 01:04:43
System.gc (); method does not enforce finally put method.
b = false
not execute
if (b)
; System.out.println ("Empty");
wudao60
2012-02-25 01:44:16
Tank tank = new Tank (); / / System.gc (); recovery does not refer only to the object pointed
xuxiaochun531724
2012-02-25 02:02:03
finally-> finalize
yangbbbbbbbbbbbb
2012-02-25 02:38:00
b then you have been false Even if you do not know really recovered ah
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.