There are times, however, in which you do not want GC to kick in. Where you no longer need a particular object, but you may need a new, "clean" one very shortly. If not handled well, this can result in a lot of new memory being allocated in a short amount of time; memory which needs to be cleaned up by GC.
In such instances, however, you may also want things to be performant. The most common case is that of a real-time game, in which you want to create new, similar objects and get rid of them in quick succession. But, if you're not careful, when GC runs it can freeze the page while it works its magic. How do you avoid this? By caching and reusing your objects.
This gist is meant as a quick and simple example of how to implement and use such a memory-management method. The code is fully commented with annotations, designed to teach you what exactly is going on here. As it's fairly straightforward to implement, feel free to make your own version for your own code, move things around or remove features you won't be needing.
And... Happy coding!