Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

plz System.gc() example

 
kanaz tarazen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic