Sharing objects across an application with the flyweight pattern
The flyweight pattern is used to minimize memory usage or computational cost by sharing as much as possible with similar objects. The flyweight pattern was described by the GoF author group.
Motivation
When a newly developed application uses many objects that are not required by the client. Memory maintenance costs can be high not only because of the large number of instances but also because of the creation of a new object. In many cases, such groups of objects can be successfully replaced by a relatively small number of instances. These instances can be transparently shared between the desired clients. This will reduce the pressure on the garbage collection algorithm. In addition, an application can reduce the number of open sockets when instances use such communication types.
Finding it in the JDK
The flyweight pattern can easily be found in the JDK. It may not be obvious to many. For example, in the implementation...