Forums Register Login

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

+Pie Number of slices to send: Send
what is the difference b/w Runtime.gc() and System.gc()? which one is best?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Not a servlet question. Moved to Java in general.
+Pie Number of slices to send: Send
The API documentation of System.gc() says:

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

Runtime.getRuntime().gc()


There's your answer.
+Pie Number of slices to send: Send
From the System.class
Personally I use System.gc(), because this is less code typing
+Pie Number of slices to send: Send
 

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.
And tomorrow is the circus! We can go to the circus! I love the circus! We can take 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 851 times.
Similar Threads
Runtime.gc() and System.gc()
System.gc() vs Runtime.gc()
Garbage Collection
Garbage Collection
System.gc() and Runtime.gc()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:26:51.