44

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

dogbane
  • 266,786
  • 75
  • 396
  • 414

4 Answers4

78

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,262,500
  • 529
  • 4,410
  • 5,250
  • 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
21

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
  • 124,308
  • 23
  • 334
  • 268
4

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

Chris Frederick
  • 5,482
  • 3
  • 36
  • 44
Thomas Pornin
  • 72,986
  • 14
  • 147
  • 189
2

Garbage Collection is the process of reclaiming the runtime unused memory by destroying the unused objects. Java Garbage Collection is the process by which Java programs perform automatic memory management. Java programs compile into bytecode that can be run on a Java Virtual Machine (JVM).

To enable Eclipse garbage collector button & see the status of the memory, to the following steps:

enter image description here

  1. Click on Windows Drop-Down Menu.

  2. Select Preferences.

  3. Tick/Enable Show Heap Status

enter image description here

  1. Click Apply & Close

Now the GC button & Memory Status is visible & you can use it to reclaim the memory which is no longer being used by a Java application and to recycle this memory for other uses.