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.

Avoiding memory leaks

Avoiding memory leaks

- [Instructor] How to avoid memory leaks? Of course, this depends a bit on the exact system and language, but let's have a look at Python. How to avoid memory leaks in Python? Well, in order to answer that question, let's start with creating some memory leaks in Python. When Python runs out of memory, you get a memory error. An easy one to run out of memory is to load a file that is too large. This is actually something that can easily happen when working with large data sets or by keeping references unnecessarily. Data can be fetched using special generator functions or processing it in batches instead. The generator functions return an iterator to loop over the data without having all the data in the RAM. There are actually solutions to avoid working with huge data sets in the memory that can be used out of the box, such as TensorFlow or Keras. This way, you can operate on large data sets and get the data only…

Contents