Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Java garbage collector clean stack memory?

Tags:

java

Is the garbage collector in Java used for clearing unused objects from heap memory only, or does it actually lend a hand in cleaning the stack memory too?

like image 203
Nav Avatar asked Dec 04 '11 17:12

Nav


2 Answers

The only things that lives on the stack are references and instances of primitive types. Both of those are ignored by the garbage collector.

like image 193
Etienne de Martel Avatar answered Oct 11 '22 05:10

Etienne de Martel


There is no garbage that lives on the stack.

like image 25
Oliver Charlesworth Avatar answered Oct 11 '22 03:10

Oliver Charlesworth