Python for the .NET developer Transcripts
Chapter: Course conclusion
Lecture: Memory management review
0:00 We saw how Python and .NET varied
0:02 in their memory management story.
0:05 .NET is a mark and sweep generational garbage collector.
0:08 Python primarily, for almost everything it does
0:12 uses deterministic reference counting.
0:15 There's no real direct memory management in Python
0:17 just like in C#.
0:19 However, there are no value types
0:21 and reference types divide.
0:22 It's all reference types, even numbers.
0:24 Those are all allocated on the heap
0:26 and memory management is mostly reference counting
0:29 unless you run into a cycle.
0:31 We saw that that's the great Achilles' heel
0:34 of reference counting.
0:35 For that, we're going to have a garbage collector
0:37 that can come up and pick up the leftover cycles for us
0:40 just in case.
0:42 We also saw the memory clean-up is deterministic.
0:45 You can say it's exactly happening here
0:48 not when the garbage collector decides to run
0:50 and eventually the background thread gets around to it.
0:52 No, it runs right as the last reference is dropped
0:55 as long as it's not a cycle.
0:57 Unlike a mark and sweep compacting garbage collector
1:00 memory is not compacted
1:01 but fragmentation is somewhat handled through constructs
1:04 called blocks, pools, and arenas.
1:06 Give you a couple articles if you want to dig in deeper.
1:09 You generally don't need to know a whole lot more than that
1:11 to be efficient with Python
1:13 but it is important to understand a little bit
1:15 of what's happening behind the scenes
1:17 because you're not explicitly doing any of this
1:19 which is great. But knowing how it works
1:22 always good to know.