Flyweight is a design pattern that minimizes an object's memory use by sharing as much of its data as possible with other similar objects. It is one of the Gang of Four's structural design patterns. When using this tag on implementation heavy questions - tag the code language the implementation is written in.
Flyweight is a design pattern that minimizes an object's memory use by sharing as much of its data as possible with other similar objects. It is a way to use objects in large numbers when a simple repeated representation would use an unacceptable amount of memory. Often some parts of the object state can be shared, and it is common practice to hold them in external data structures and pass them to the Flyweight objects temporarily when they are used.
A classic example usage of the Flyweight pattern is the data structures for graphical representation of characters in a word processor. It might be desirable to have, for each character in a document, a glyph object containing its font outline, font metrics, and other formatting data, but this would amount to hundreds or thousands of bytes for each character. Instead, for every character there might be a reference to a Fyweight glyph object shared by every instance of the same character in the document; only the position of each character (in the document and/or the page) would need to be stored internally.
Flyweight is one of the Gang of Four's structural design-patterns, first published in Gamma et al.'s book "Design Patterns: Elements of Reusable Object-Oriented Software".