Question:
How can you force garbage collection?
Answer:
You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately. Source: CoolInterview.com
You can't force GC but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately. Source: CoolInterview.com
Answered by: gourav shivhare | Date: 11/10/2009
| Contact gourav shivhare
User cannot force the garbage collection, instead user can send a request to JVM asking for doing the garbage collectin with System.gc() method.
Once, JVM recieves the gargabe collection request and if memory really needs to be collected (like if memory out of condition situations occur) then JVM automaically runs the thread to do the garabge collection.
Source: CoolInterview.com
Answered by: Venu | Date: 1/10/2010
| Contact Venu
Garbage collection can be requested two ways System.gc() and Runtime.gc(). But when it happen is implementation depends on implementation Source: CoolInterview.com
Answered by: vinod | Date: 2/24/2010
| Contact vinod
If any object is no longer required then If you want to clean that object from the heap .We can do that by clling Sysem.gc() method. Source: CoolInterview.com
Answered by: Bhaskar Reddy | Date: 5/12/2010
| Contact Bhaskar Reddy
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|