1

I am learning Java internals and this can be a naive question. I understood the concept of garbage collection in Java that JVM decides when to perform garbage collection but we can only REQUEST JVM by using System.gc() . So my question is that if System.gc() does not force the garbage collection then what is the importance of the command? What exactly we can achieve by this call? What are the considerations while supporting System.gc() call? Essentially the question is why Java provide System.gc() call?

mohan.t
  • 257
  • 5
  • 12
  • @dasblinkenlight: The question which you have given asks about the functionality of System.gc(). This question essentially ask why do Java supports System.gc() if we can not achieve almost anything from it? please let me know what are your thoughts while marking this question duplicate. thanks – mohan.t Oct 23 '14 at 16:59
  • The answers to the other question discuss the usefulness of `System.gc()` as well - for example, [this answer](http://stackoverflow.com/a/66694/335858) mentions a case when a call of `System.gc()` actually makes sense. – Sergey Kalinichenko Oct 23 '14 at 17:09
  • 1
    @dasblinkenlight That answer doesn't seem very satisfying to me. I have to agree with OP and vote for reopen on this one. – Ingo Bürk Oct 23 '14 at 17:41
  • The answer is that it is only giving a *hint* that the application thinks it’s a good moment for garbage collection. That hint might be used by the JVM or not. I don’t think, there is really much more to say about it, so there’s no reason to reopen. – Holger Oct 23 '14 at 17:48
  • 1
    @Holger I don't see more reason either, neither does the OP. But who is to say we aren't wrong. I find that a rather unsatisfying reason to deny others the chance to answer because it builds on the assumption that you have full knowledge. Besides, "there is nothing to say" hardly is a reason for closing a question. The current reason, IMHO, is unjustified. – Ingo Bürk Oct 23 '14 at 17:50
  • @Ingo Bürk: well, as I don’t expect the original designer of the Java 1.0 API to show up to answer this question, everything beyond a simple “it’s a hint, not mandatory” answer would be “primarily opinion based”. – Holger Oct 23 '14 at 17:53
  • @Holger That I can agree on. Though I still think it's a shame this can't be answered in case there are interesting answers. But maybe SO just isn't the place for it. – Ingo Bürk Oct 23 '14 at 17:56
  • I agree with IngoBürk. @Holger Before posting this question, I went through [When does System.gc() do anything](http://stackoverflow.com/questions/66540/when-does-system-gc-do-anything?lq=1) and felt that the answers are related to this question but do not focus on what I have asked. – mohan.t Oct 23 '14 at 18:34
  • @mohan.t: I think there are some answers addressing the “possible use cases” part of your question. However, if you want to narrow your question down to the “why Java provide System.gc() call [exactly]” part, that can be only answered by the designers of that API. Even if you’re right and this question is not a duplicate, there is no benefit in re-open it just to close it for “primarily opinion based” or “off-topic” then. – Holger Oct 24 '14 at 08:07

0 Answers0