Python for the .NET Developer Transcripts
Chapter: Course conclusion
Lecture: Memory management review

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw how Python and .NET varied in their memory management story. .NET is a mark and sweep generational garbage collector.
0:09 Python primarily, for almost everything it does uses deterministic reference counting. There's no real direct memory management in Python
0:18 just like in C#. However, there are no value types and reference types divide. It's all reference types, even numbers.
0:25 Those are all allocated on the heap and memory management is mostly reference counting unless you run into a cycle.
0:32 We saw that that's the great Achilles' heel of reference counting. For that, we're going to have a garbage collector
0:38 that can come up and pick up the leftover cycles for us just in case. We also saw the memory clean-up is deterministic.
0:46 You can say it's exactly happening here not when the garbage collector decides to run and eventually the background thread gets around to it.
0:53 No, it runs right as the last reference is dropped as long as it's not a cycle. Unlike a mark and sweep compacting garbage collector
1:01 memory is not compacted but fragmentation is somewhat handled through constructs called blocks, pools, and arenas.
1:07 Give you a couple articles if you want to dig in deeper. You generally don't need to know a whole lot more than that to be efficient with Python
1:14 but it is important to understand a little bit of what's happening behind the scenes because you're not explicitly doing any of this
1:20 which is great. But knowing how it works always good to know.

Talk Python's Mastodon Michael Kennedy's Mastodon