How can I see the impression of the Garbage Collector?
Hello Experts,
I want to get acquainted with the Garbage Collector.
I'm pretty new to Java, so far I have written very simple programs. I 'm using the System.gc() statement in my codes, but I can't see the Garbage Collector's influence.
Can someone give me a little code or explaination where I can see clearly the impact of the garbage collector? Is there any function to display the unreferenced objects or memory usage?
At the moment I try to test the functionality of the gc with the following code:
Code:
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Iterator;
public class Garbage{
public static void main(String[] args)
{
Queue qu = new PriorityQueue();
for (int i=0;i< 100;i++)
{
String str=new String(Integer.toString(i)+"pear");
qu.add(str);
[B]System.gc(); [/B]
}
Iterator it = qu.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
}
How can I tranform this code to see the impression of gc?
I would be very grateful for any help! :)