Garbage Collections

Q1: Which statement is true?

A Memory is reclaimed by calling Runtime.gc().

B Objects are not collected if they are accessible from live threads.

C An OutOfMemory error is only thrown if a single block of memory cannot be found that is large enough for a particular requirement.

D Objects that have finalize() methods always have their finalize() methods called before the program ends.

ANS:B - Objects are not collected if they are accessible from live threads.

Option B is correct. If an object can be accessed from a live thread, it can't be garbage collected. Option A is wrong. Runtime.gc() asks the garbage collector to run, but the garbage collector never makes any guarantees about when it will run or what unreachable objects it will free from memory. Option C is wrong. The garbage collector runs immediately the system is out of memory before an OutOfMemoryException is thrown by the JVM. Option D is wrong. If this were the case then the garbage collector would actively hang onto objects until a program finishes - this goes against the purpose of the garbage collector.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.