Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization 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