File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collection

 
durga krishna
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
what do u mean by this?
Circular references do not prevent objects from being garbage collected.
thanx
durga
 
Hima Mangal
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi durga..
can u give some example code with ur ques pls??

------------------
Hima
 
Revati Pathak
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try This Example
// ******************
class Test1 {
public static void main(String arg[]) throws Exception{
MyObj a = new MyObj("a");
MyObj b = new MyObj("b");

//circular reference here
a.o = b;
b.o = a;
a = null;
b = null;
// a and b are both eligible for GC now

MyObj c = new MyObj("c");
c.o = new MyObj("d"); //when c dies, d dies too.
c = null;

// an infinite loop here
// use ^c to kill it

MyObj[] objAry = new MyObj[1024];
int i = 0;
while (true){
// suggest JVM to GC
System.gc();

// use more memory here
i %= 1024;
objAry[i] = new MyObj("X" + i);

i++;
Thread.sleep(5); // Give CPU some breath time
}
}
}
class MyObj {
MyObj o;
String s;
long[] ary = new long[4096]; // make MyObj big

MyObj(String s) {
this.s = s;
}

protected void finalize() throws Throwable {
// Make GC visible
System.out.println(s + ": I am dying");
super.finalize();
}
}
// ******************

[This message has been edited by Revati Pathak (edited March 27, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic