By: AshQuestion: How can you force garbage collection of an object?
A. Garbage collection cannot be forced.
B. Call System.gc()
C. Call System.gc(), passing in a reference to the object to be garbage-collected
D. Call Runtime.gc().
E. Set all references to the object to new values(null , for example).
Answer:A is correct. Garbage collection cannot be forced. Calling System.gc() or Runtime.gc() is not 100 percent reliable, since the garbage-collection thread might defer to a thread of higher priority; thus B and D are incorrect. C is incorrect because the two gc() methods do not take arguments; in fact, if you still have a reference to pass into the method, the object is not yer eligible to be collected. E will make the object eligible for collection the next time the garbage collector runs.
Most Viewed Articles (in Certification )
Latest Articles (in Certification)
Comment on this tutorial
- Data Science
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews
Subscribe to Tutorials
2. GC.Collect is for .net not for java don't get conf
View Tutorial By: asin at 2013-06-27 15:47:35