Skip to content

Instantly share code, notes, and snippets.

@wojciak
Created August 4, 2014 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wojciak/836170080383d0cf04f3 to your computer and use it in GitHub Desktop.
Save wojciak/836170080383d0cf04f3 to your computer and use it in GitHub Desktop.
Don't bleed arrays
// Cleaning up pixi sprite reference arrays
// Don't
var elements = [];
function() {
elements.forEach(function (element) {
element.parent.removeChild(element);
element = null;
});
elements = []; // If the elements array is referenced somewhere you're bleeding arrays
}
// Please do
var elements = [];
function() {
elements.forEach(function (element) {
element.parent.removeChild(element);
element = null;
});
while (elements.length > 0) {
elements.pop(); // use only one elements array - clean & fast
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment