This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes plz System.gc() example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "plz System.gc() example" Watch "plz System.gc() example" New topic
Author

plz System.gc() example

kanaz tarazen
Greenhorn

Joined: May 26, 2005
Posts: 1
hai guys,

can anybody give me a small example on how garbage collection takes place by using System.gc() ?

thanx

kanaz
Vipin Das
Ranch Hand

Joined: Jul 05, 2004
Posts: 47
Using System.gc() you can just request to run the garbage collector. It may or may not run.
public static void main(String args[[]){
new xyz();
System.gc();
//if gc runs it will garbage collect the above object


}
class xyz{
String p[];
xyz(){
p = new String[200];
}
}

[ May 26, 2005: Message edited by: Vipin Das ]
[ May 26, 2005: Message edited by: Vipin Das ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: plz System.gc() example
 
Similar Threads
About GC
if Java has garbage collection, then why
gc yet again!
System.gc()
destroy objects