Creating a destroy function
Always implement a function – called destroy() – on every object that you create, and call it every time you finish working with an object. The function contains all the code necessary to remove all references to and from the object (excluding the reference which was used to call the function), so you make sure the object leaves your application totally isolated, and is easily recognized by the GC.
// Create this in every object you use
// Remove event listeners
// Remove anything in the display list
// Clear the references to other objects, so it gets totally isolated
// When you want to remove the object, do this:
// And then null the last reference to it