class A{
static int j=0;
A(){
j++;
System.out.println("object created"+j);
}
protected void finalize(){
j--;
System.out.println("object deleted"+j);
}
public static void main(String a[]){
//Thread t1 = new Thread();
A[] a1 = new A[10];
for(int i=0;i<10;i++){
a1[i]=new A();
}
for(int i=0;i<10;i++){
a1[i]=null;
}
System.gc();
try{
Thread.sleep(100);
}catch(Exception e){
System.out.println(e);
}
}
}
static int j=0;
A(){
j++;
System.out.println("object created"+j);
}
protected void finalize(){
j--;
System.out.println("object deleted"+j);
}
public static void main(String a[]){
//Thread t1 = new Thread();
A[] a1 = new A[10];
for(int i=0;i<10;i++){
a1[i]=new A();
}
for(int i=0;i<10;i++){
a1[i]=null;
}
System.gc();
try{
Thread.sleep(100);
}catch(Exception e){
System.out.println(e);
}
}
}
No comments:
Post a Comment