Hej

Mam mały program:

import java.util.ArrayList;
import java.util.List;

class Te{
    String t = "";
    public void set(String s) {
        t = s;
    }
    
    public String get() {
        return t;
    }
    
    public void change() {
        t += "dsada";
    }
    
    public void finalize() {
        t = null;
        System.err.print("f");
    }
}

class Ty{
    Te t = null;
    public void set(Te s) {
        t = s;
    }
    
    public Te get() {
        return t;
    }
    
    public void change() {
        t.change();
    }
}

public class Tests {

    public static void main(String[] args) {
        String st = "napisnapisnapisnapisnapisnapisnapisnapis";
        Te t = new Te();
        t.set(st);
        t.change();
        System.out.println(st + " " + t.get());
        Ty ty = new Ty();
        ty.set(t);
        ty.change();
        System.out.println(ty.get().get() + " " + t.get());
        
        
        System.out.println("-1 " + Runtime.getRuntime().totalMemory());
        List<Te> list = new ArrayList<Te>();
        for (int i=0; i<1000; ++i) {
            //list.clear();
            list = new ArrayList<Te>();
            
            try {
                Thread.sleep(5000);
                System.gc();
                
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int j=0; j<100000; ++j) {
                Te t2 = new Te();
                t2.set(st);
                list.add(t2);
                t2 = null;
            }
            System.out.println("");
            System.out.println(i + " " + Runtime.getRuntime().totalMemory());
            list.clear();
            list = null;
        }
    }
}

Jak widać nie robi za wiele ciekawego. Po porstu sprawdzenie gc. Ale po uruchomieniu w Eclipsie, po paru obiegach zewnętrznej pętli rozwala grafike w Windowsie (zmienia tryb graficzny). Wie ktoś może dlaczego ??