wsh - in JavaScript, when finished with an object created via new ActiveXObject, do I need to set it to null? -


in javascript program runs within wsh , creates objects, let's scripting.filesystemobject or arbitrary com object, need set variable null when i'm finished it? eg, recommended this:

var fso = new activexobject("scripting.filesystemobject"); var filestream = fso.opentextfile(filename); fso = null;  // recommended?  necessary?  ... use filestream here ... filestream.close(); filestream = null;  // recommended? necessary? 

is effect different letting vars go out of scope?

assigning null object variable decrement reference counter memory management system can discard resource - feels it. reference counter decremented automagically when variable goes out of scope. doing manually waste of time in cases.

in theory function using big object in first , big object b in second part more memory efficient if set null in middle. not force mms destroy a, statement still waste.

you may circular references if fancy class design. breaking circle hand may necessary - perhaps avoiding such loops in first place better.

there rumours ancient database access objects bugs avoided zapping variables. wouldn't base programming rules on such voodoo.

(there tons of vbscript code on internet full of "set x = nothing"; when asked, authors tend talk 'habit' , other languages (c, c++))


Comments