Python Memory Management and Tips Transcripts
Chapter: Efficient data structures
Lecture: Disabling the gc revisited

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I hope this article from Instagram about how they disabled Pythons garbage collection and used less memory and not more made an impression on you.
0:09 It sure did on me when I first heard about it. It honestly kind of blew my mind. What was it that made this possible? Why could they do this? Well,
0:18 let's go back to the Python documentation. Right here in the center line bit, once again
0:22 it says "you can disable the collector if you are a sure your program does
0:27 not create reference cycles", and I would change that a little bit like "it doesn't create too many reference cycles" because, you know,
0:34 if it's short lived and it creates a couple, who cares, right? If it leaks a little bit of memory. But if, like the core thing you're doing,
0:40 the core data you're working with require cycles, well, I guess you can't do it.
0:46 So what we're going to do in this next section is we're gonna look at a
0:48 situation that has reference cycles and say "is there some way to restructure the algorithm so
0:54 we no longer have these cycles in our data?" And then it would be possible to
0:59 turn off the garbage collector. Not necessarily saying we have to do that,
1:03 but we're going to talk about these cycles and basically avoiding creating them, using different algorithms and slightly different data structures.

Talk Python's Mastodon Michael Kennedy's Mastodon