Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

GC question  RSS feed

 
wilbin chan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True or false:
Low memory situations cause GC to run?
I read somewhere that GC only runs after the heap has been exhausted, and that when it runs, all other threads are suspended. I've somewhat confirmed this particular behavior in Sun reference implementation JVM's. Is this behavior specified by Java or JVM dependent?
Anyhow, the answer to my first question would seem to be true, but I am not sure. A related question would be 'does a heap allocation failure force gc to run'? Again I think the answer id yes, just from observing Sun's jvm.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is false.
Though it is a nice to have feature, garbage collection is not guaranteed and hence your program can run out of memory!! Remember that GC is vendor specific and may not depend on howmuch memory is left on the heap
Ajith
 
umang bhartia
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i fully agree with Ajith. U can never force GC, and u can never know when it is activated, so there can b possibility of program going out of memory. So a heap allocation failure can never force gc to run.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!