Flyweight Pattern
Updated 2026-07-30
Summary
In computer programming, the flyweight software design pattern refers to an object that minimizes memory usage by sharing some of its data with other similar objects. The flyweight pattern is one of twenty-three GoF design patterns. In other contexts, the idea of sharing data structures is called ha…
Definition
A design pattern that reduces memory usage by sharing as much data as possible. It divides object state into intrinsic state (shareable) and extrinsic state (non-shareable). Scaffold use: Optimize resource allocation. When dealing with a large number of similar tasks or objects, extract the invariant 'common denominator' for reuse, and handle only the differences separately to reduce system load.
Introduction
How to use
Optimize resource allocation. When dealing with a large number of similar tasks or objects, extract the invariant 'common denominator' for reuse, and handle only the differences separately to reduce system load.
Mechanism
Reduce memory/resource usage by sharing the common parts of a large number of fine-grained objects, replacing repetition with sharing.
Practice
In progress 0/1Practice this model in one real situation:
Cases
- Character style sharing in text editors; many similar objects in games.
Common pitfalls
- Sharing the wrong objects leads to coupling; ignoring thread safety; over-engineering.
Sources
Source support: Explicit
References currently contain only Wikipedia links; primary sources still need review.
- en.wikipedia.orghttps://en.wikipedia.org/wiki/Flyweight_patternverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS