This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Forcing garbage collector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Forcing garbage collector" Watch "Forcing garbage collector" New topic

Forcing garbage collector

vicky malhotra

Joined: Feb 05, 2005
Posts: 16
Is there any way by which we can force garbage collector to act? I mean its true that garbage collector will act on any object for which there is no reference. But the garbage collector works on its own. Can we somehow force it to run?
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071

You can 'recommend' (System.gc()) it to run, but there are not garuntees.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
On the other hand, I have found that the garbage collector in j2se will actually finalize and delete all eligible objects in small programs when System.gc() is called. I think this is just a courtesy to students and doesn't change the standard.

Mike Gershman
SCJP 1.4, SCWCD in process
I agree. Here's the link:
subject: Forcing garbage collector
Similar Threads
Garbage collection query
finalize () method
Q:65 on Barry Boone Exam
can we force Garbare collector
Garbage Collector Question