12.3 The Flyweight pattern
The Flyweight pattern is a memory optimization pattern. Novice Python programmers tend to ignore memory optimization, assuming the built-in garbage collector will take care of it. Relying on the built-in memory management is the best way to start. Indeed, for the most part, Python lets us ignore memory management.
There are a few cases where memory limitations surface. One example is very large data science applications. In these applications, memory constraints can become barriers, and more active measures need to be taken. The other common example is very small Internet of Things devices; for these, memory management can also be helpful.
The Flyweight pattern ensures that objects that share a state can use the same memory for their shared state. It is normally implemented only after a program has demonstrated memory problems. Bear in mind that premature optimization is the most effective way to create a program that is too complicated...