Garbage Collection
The process where the interpreter frees up memory when not in use to make it available for other objects.
Reference Counting
It counts the number of times an object is referenced by other objects.
When references to an object are removed, the object reference counter for that object reduces.
When the reference count becomes 0, the object is then de-allocated from the memory.
Stack Memory
It is called stack memory because allocation happens in the function call stack.
Size of memory to be allocated is known by the compiler, and whenever a function is called, its variables get memory allocated on the stack.
Any local variable assignments are stored temporarily in the stack memory where it is deleted once the function returns.
Heap Memory
It is called heap because it is a piece of memory space available to the programmers to allocate and de-allocate memory.
The variables are needed outside method or function calls or are shared within multiple functions globally are stored in heap memory.