Skip to main content
Loading page…
Python Mastery
Chapter 13
Lesson 4 of 4
Memory, Reference Counting & __slots__
Contents
Notes
Tutor
Concept
How CPython Manages Memory: Reference Counting
Loading activity…
Previous
1 / 13
Continue
Contents
Notes
Discussion
Tutor
30 min
13 activities
0 of 13 done
In this lesson
1
How CPython Manages Memory: Reference Counting
2
The Cyclic Garbage Collector
3
Measuring Memory with sys.getsizeof
4
Small-Int Caching and String Interning
5
__slots__: Trading Flexibility for Memory
6
__slots__ in Action: Memory Comparison
7
Weak References: Hold Without Owning
8
Implement a Slotted Record Class
9
Reference Counting Edge Case
10
Memory Management Concepts Quiz
11
Classify: Reference Count Impact
12
When to Use __slots__
13
Your Memory Model Synthesis
Objectives
Explain CPython's reference counting mechanism and when it fails
Describe the cyclic garbage collector and the objects it handles
Measure object memory usage with sys.getsizeof and understand its limits
Explain small-int and string interning as CPython optimizations
Implement __slots__ to reduce per-instance memory and speed up attribute access
Use weakref to hold references without preventing garbage collection
Chapter 13 · The Python Data Model & Memory
Objects, Identity & References
Mutability, Hashability & Shared State
Copying: Shallow vs Deep
Memory, Reference Counting & __slots__
Previous: Copying: Shallow vs Deep
Next: Dunder (Magic) Methods