Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the difference b/w Runtime.gc() and System.gc()? which one is best?  RSS feed

 
sujitha reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference b/w Runtime.gc() and System.gc()? which one is best?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think both do the same thing.But when we call gc , then also it is not guaranted that this would really remove the garbage objects from the heap releasing memory.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a servlet question. Moved to Java in general.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API documentation of System.gc() says:

The call System.gc() is effectively equivalent to the call:

Runtime.getRuntime().gc()


There's your answer.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the System.class
Personally I use System.gc(), because this is less code typing
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bauke Scholtz:
From the System.class
Personally I use System.gc(), because this is less code typing


Personally, I never use either -- and neither should you. It's extraordinarily rare that calling one of these methods actually improves an application, and often it has the reverse effect.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!