From the course: Programming Foundations: Memory, Pointers, and Garbage Collection

Unlock the full course today

Join today to access over 25,200 courses taught by industry experts.

Garbage collection

Garbage collection

- [Narrator] So freeing up the memory of the heap can be done by a process called garbage collection. Some languages like C and C++ require manual garbage collection by code. Typically, it's not called garbage collection then. Languages that have an automatic garbage collection building are for example, CCR, Java, Python and actually many other high level languages. There are some common errors that are not happening when we use a garbage collector. First of all, the dangling pointer bugs can be avoided. This is when the developer did free up the memory space but the pointer is still pointing to the old place where a certain variable is stored. You can imagine that this can lead to unpredictable events such as a pointer returning a surprise value, when the memory location has been reassigned to another value. Another common problem that developers with automatic garbage collection don't run into is the bug of freeing up a…

Contents