If I have a function like this:
function doSomething(param){
var tempV = param;//should I even assign it to another variable?
tempV.css('color','red');
tempV = null;//Is this necessary?
//Should I do param = null too?
}
And I run this(the code below) somewhere, possibly in another function:
var elementBeingPassed = $('#someElement');
doSomething(elementBeingPassed);
anotherFunctionSimilarToDoSomething(elementBeingPassed);
elementBeingPassed = null;
Would this create a memory leak? Are all the x = null
statements needed?
What I want to do is to not have to query the same element all over again in all the functions, instead just query it once and pass it on.
Those variables are about to go out of scope anyway.
Therefore, setting them to null
makes no difference.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.