IntelliJ Java IDE
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GC question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "GC question" Watch "GC question" New topic
Author

GC question

wilbin chan
Greenhorn

Joined: Oct 09, 2000
Posts: 6
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

Joined: Mar 17, 2000
Posts: 5781
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


Open Group Certified Master IT Architect.
Sun Certified Architect(SCEA).
umang bhartia
Ranch Hand

Joined: Sep 29, 2000
Posts: 60
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.
 
IntelliJ Java IDE
 
subject: GC question
 
Threads others viewed
Forcing Full GC
garbage collector & operating system memory...
One Question about GC
GC - Thread safe
GC
MyEclipse, The Clear Choice