Using Large Numbers of Objects
Learn which design patterns to use to achieve efficiency when using a large number of object instances.
Problem statement
Let’s imagine that we have a requirement to use many similar objects in our application. Perhaps, we’re building a distributed application based on
In this situation, purely using built-in language features will probably be problematic. We’ll need to instantiate every single one of these objects. Once the object is out of scope, our runtime will need to get rid of it to free up the memory. If we need a similar object again, we’ll instantiate it again.
If we follow this approach, we’ll probably experience a performance hit. Instantiating a new object each time we need to use it is a relatively expensive process. The runtime will need to allocate memory for it and populate those chunks of memory with new values.
If we’re using similar objects in different ...