Originally posted by gylph knor:
hi! can anybody tell that why this program not printing "dead" but is rather throwing this exception after creating a few objects
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 1.5 94%.
The greatest glory in living lies not in never falling, but in rising every time we fall.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Originally posted by Ankit Garg:
but the sleep is blocking JVM from destroying your objects for about 1000 seconds(this value might be wrong). So when the garbage collector runs it is blocked for 1000secs(so no objects can be garbage collected for that time period) in that time the loop creates so many objects that the JVM is out of memory.....
After that I want to ask that is Garbage collector a thread. As the output of this program goes, dead is displayed only once. This means that garbage collector is a thread(daemon) and the sleep method stops it from garbage collecting any objects.
Or is a separate garbage collector invoked to destroy every object???
Originally posted by Jesper Young:
About your last question: I don't know, but it doesn't matter. What happens is that the program very quickly creates lots of objects, but destroying each of those objects takes a long time because of the 1000 seconds pause in the finalizer. It doesn't matter if there is only one garbage collector or if there is a separate garbage collector for every object (think about it!) - simply because objects are created much faster than they are destroyed, you'll get an OutOfMemoryError.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links