Speaker
Nina Zakharenko
Material
Note
- How does Python store object in memory
- name -> reference -> object
- Python Object Types
- Simple (e.g., numbers, strings)
- Containers (dict, list, user defined-class)
- Every Python object holds
- type
- value
- ref count
- Reference Count
- Decrease ref count
del
- remove the name as a reference instead of delete the object
- decrease the reference count by 1
- going out of scope
- Decrease ref count
- Global Namespace
- never go out of scope → refcount never reach 0
- Avoid putting large or complex objects in the global namespace
- Common Garbage Collection Techniques
- Reference Counting
- Concept
- add / remove ref
- delete object if refcount reaches 0
- The good
- Easy to implement
- When refcount is 0 objects are immediately delete.
- The bad
- space overhead
- execution overhead
- The ugly
- not thread safe
- doesn't detect cyclical ref
- Concept
- Tracing (mark and sweep)
- Reference Counting
- What algorithm does Python use?
- Reference Counting + Generational
__slot__
- Attribute Declarations
- When to use
- If we're going to create lots of instances
- If we know the properties in advance