Garbage Collection – Need for Garbage Collection in a Stack-Based Language

garbage-collectionstack-oriented

What is the need for garbage collection (GC) in a stack-based language? In a language like Forth or RPL (on HP calculators), is there a need for garbage collection?

I would think, since output is popped off the stack, that there wouldn't be any need. Am I missing something?

Best Answer

GC is normally applied to memory allocated on the heap. I'm not familiar with Forth or RPL, but if there is no heap, and everything is stored on a global stack instead, then there's nothing for GC to do.