Nina Zakharenko - Memory Management in Python - The Basics - PyCon 2016
Why Stack Overflow recommends it
Stack Overflow users link it as background when asking about Python's garbage collector generations, __slots__ memory savings, and how the interpreter handles object allocation and reference counts.
Recommended by 0 people across 0 different months, 2016 to 2019.
What it is
A PyCon 2016 conference talk by Nina Zakharenko introducing how memory management works in CPython. It covers reference counting, generational garbage collection, weak references, __slots__, and the Global Interpreter Lock.
What people said
Cites alecxe · 2016-06 · Stack Overflow · on “Watching generation lists during a program run”
The Story: During Nina Zakharenko's PyCon talk [this video] on Memory Management in Python, she explains the way the generational garbage collection works in Python noting that: Python maintains a list of every object created as a program is run. Actually, it makes 3: generation 0 generation 1 generation 2 The question: To gain more understanding in Memory Management in Python and for the purpose of debugging memory leaks, how can I observe/watch what objects are added and removed from all the 3 generation lists during a program run ? I've looked through the gc module [LINK] , but have not found a relevant method to get the current generation lists values.
Cites Jonah Bishop · 2018-10 · Stack Overflow · on “Does Python's interpreter compare values when allocating memory?”
I just watched this informative video [this video] on memory management in Python. In it, the presenter used the following code example (at about the 4:15 mark): x = 300 y = 300 In this case, we have two names ( x and y ), each pointing at a value of 300. How did Python, when executing the y = 300 line, know that it didn't need to allocate memory but rather increase the reference count, since memory for that value had already been allocated (through x )? Is the interpreter comparing values on each instantiation? If so, how does it keep track of the values it already knows about (I would assume it would do so using a dict )? Suppose I introduced a new variable: z = 100 + 200 Would z end up simply
Cites Matt · 2019-03 · Stack Overflow · on “Understanding size of class, namedtuple and __slots__ in Python 3.7”
After watching Nina Zahkarenko's Python Memory Management talk at Pycon2016 ( link [this video] ), it seemed like the dunder method __slots__ was a tool to reduce object size and speed up attribute lookup. My expectation was that a normal class would be the largest, while a __slots__ / namedtuple approach would save space. However, a quick experiment with sys.getsizeof() seems to suggest otherwise: from collections import namedtuple from sys import getsizeof class Rectangle: '''A class based Rectangle, with a full __dict__''' def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height class SlotsRectangle: '''A class based Rectangle with __slots__ define