I find the Object Pool pattern extremely useful.
For starters, I can easily count how many instances of a class instantiated or replace a specific instance
without worrying about which objects might still hold a reference to the old version.
Here’s a simple constructor example with a built-in registration component. New instances register
to the class’s static pool attribute. This pool, keyed by the object’s id, will ensure we only
have one copy with that id. If we new up Class with an id that already exists, we effectively
replace the current instance–there’s no need to hold a reference (I do it in the example below to
demonstrate the replacement).
Some pool management methods may be statics, like getInstance. Others may be on the instances
using prototype inheritance, like the destroy method below.