Forums Register Login

System.gc() vs Runtime.gc()

+Pie Number of slices to send: Send
* What is the differance between System.gc() and Runtime.gc() ?
+Pie Number of slices to send: Send
System.gc() is just a convenience for Runtime.getRuntime().gc().

However, if you are genuinely a beginner, you should never be calling either of these methods.

99.9% of the time, Java will garbage-collect as appropriate and does not need you to tell it to do so. Calling one of the gc() methods does not force garbage collection to happen, either; it only suggests to the JVM that now might be a good time for some garbage collection.
+Pie Number of slices to send: Send
Read the API documentation of both of those methods. The documentation of System.gc() says:

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

Runtime.getRuntime().gc()


So, there is no difference in these two at all.
He's giving us the slip! Quick! Grab this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 11269 times.
Similar Threads
garbage collection's doubt
What is the diffrerence between System.gc() and Runtime.gc()
question on GC
what is the difference b/w Runtime.gc() and System.gc()? which one is best?
Core Java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:20:19.