Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Garbage Collection

What is the main purpose of garbage collection and when you are using the keyword pop or del to remove at element from a list for instance is this then available for garbage collection, and how does it work

2 Answers

Broderick Lemke
Broderick Lemke
13,483 Points

Garbage collection is a process that is standard through higher level languages like python. There is a garbage collector that comes through in the background and clears up memory. Whenever we declare a variable, add an item to a list, or declare a function we are taking up space in memory. When we us del() or pop() we are removing items from memory and the garbage collector can come along and free up those spaces in memory. One of the great things about high level languages is that we don't have to worry too much about garbage collection because the language takes care of it on its own. We simply need to be aware that there is a background process cleaning up memory and if we are experiencing issues with huge amounts of memory being taken up by an application, like through a memory leak, that we may need to clear out some variables.

Thanks. could you also help me understand the copy method on a loop as I am still experiencing difficulties on it. so if you use a copy method on a loop it remains the same whilst iterating through the list rather than using the original that modifies it.