null - If you nullify spent objects in javascript, are you saving possible silly garbage collections? -
if nullify spent objects in javascript, saving possible silly garbage collections?
for example.
if iterate through users in javascript:
var users = [ { firstname: "chris", lastname: "pearson" }, { firstname: "kate", lastname: "johnson" }, { firstname: "josh", lastname: "sutherland" }, { firstname: "john", lastname: "ronald" }, { firstname: "steve", lastname: "pinkerton" } ]; // data, perhaps put in table users = null;
is worth nullifying list? have science behind performance gains or if it's waste of time etc?
it's quite hard explain people why way, know it's saved bacon on many occasions in, ofcourse, c++, in javascript, there experiment find out if it's worth in javascript? find sizeof function can trust, making me cry... if has done kind of experiment, i'd grateful see have come with!
it depends on situation. example, here useless:
function putusersintable(){ var users = [ { firstname: "chris", lastname: "pearson" }, { firstname: "kate", lastname: "johnson" }, { firstname: "josh", lastname: "sutherland" }, { firstname: "john", lastname: "ronald" }, { firstname: "steve", lastname: "pinkerton" } ]; // data users = null; // useless, data gc'd anyways }
here allow data gc'd when couldn't otherwise:
function putusersintable(){ var users = [ { firstname: "chris", lastname: "pearson" }, { firstname: "kate", lastname: "johnson" }, { firstname: "josh", lastname: "sutherland" }, { firstname: "john", lastname: "ronald" }, { firstname: "steve", lastname: "pinkerton" } ]; // data // event hander in dom or global variable outsidethisscope = function(){ // anonymous function has access users, // doesn't make use of console.log('hi'); } users = null; // removes reference array, // allowing gc'd }
Comments
Post a Comment