43

What happens when I press the "Run Garbage Collector" button in Eclipse? Does it just call System.gc()?

dogbane
  • 254,755
  • 72
  • 386
  • 405

3 Answers3

75

Yes, it is strictly a call to the JVM, not to an internal Eclipse function (see this thread).

Don't forget the Memory Analyzer to also check paths to garbage collection roots (in a Head Dump) if you suspect some memory leaking in your Eclipse session.

Note: that button is only available if you select the "Show Heap status" in the General section of the Eclipse preferences:

alt text

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
  • It took me a few minutes to figure out what to do for rajasti277's tip. Click the "General" item in the left panel. – GinoA May 17 '12 at 15:12
  • Thanks a lot, it helped :) – Aaron Socurites Feb 12 '16 at 13:23
  • A popular interview question is whether Garbage Collection can be enforced, and the short answer is, "no," as System.gc() merely provides a "hint" to the JVM that garbage collection should be run - i.e. it's not guarateed. Now, two questions arise: (1) What exactly does a "hint" mean in this context and (2) Does the button in Eclipse do more than simply provide a "hint?" It appears so, as the used heap memory immediately immediately decreases upon pressing it. – Ebony Maw Jun 26 '18 at 21:49
20

Yes, the System.gc() is called!

Very useful in the Eclipse –>Preferences–>General-> Show heap status

enter image description here

then you can see in the lower right corner the "trash can" to run the Garbage Collector. =)

Jorgesys
  • 119,885
  • 23
  • 317
  • 256
4

Yes, System.gc() is called when the "Run Garbage Collector" button is pressed.

Chris Frederick
  • 5,348
  • 3
  • 35
  • 42
Thomas Pornin
  • 71,088
  • 14
  • 144
  • 187