Two thousand copies
transcript
A cinema hall. Forty rows. Two thousand seats. But only three kinds of seat. And the app built two thousand copies of what a seat kind means. One per seat, for three kinds. Why?
Each regular seat builds its own details object. Regular, 200 rupees, 80 centimetres of legroom. The next seat builds another one. Identical. And the next seat, another. 1,250 regular seats. 1,250 identical copies.
The fix is a flyweight. A factory creates the regular kind once, and keeps it. Every seat holds a reference to the very same object. Not a copy. Two thousand seats. Three kind objects. The row stays with the seat, and the sold flag stays outside the kind.
Measured on CPython 3.9. A copy per seat: 313 bytes a seat. A shared kind: about 160. Half. Not more, because the seat itself stays. Newer Pythons use fewer bytes, but the half holds.
Keep what differs per seat outside the shared object. And measure before you claim.
Full breakdown in the lecture.