Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In jQuery how delete variables and functions

I've got a function in jQuery, eg.

var asd;

function dosomething(){
    for (i=0;i<=1000000;i++)
    {
    asd[i] = "(2^i)";
    }
}

How can i unset the variables after the function?

delete $asd;

With this, i can clear the variable from the memory.

But can i reach the function's destructor in jQuery and how can I unset the whole function in the function's destructor?

THE WHY

The function and all the global variables are in the memory after running a script.
If i run something by the console, after the dom ready - since the all variables are still in the memory - the program will run.

So I'd like to clear the variables on the function's desctructor, then reset the function, or make it to null.

Because it will flush the whole script from the memory, so my page will be faster. Imagine a bit larger data structure than a single function, like 100 functions and 800 global variables. After the shown, i don't need the variables anymore.

like image 617
Répás Avatar asked Aug 02 '11 12:08

Répás


1 Answers

Set it to undefined:

asd = undefined;

Update To unset a function, do:

myFunction = undefined;

You don't need the brackets. In your comment, you've misspelt undefined

like image 145
Adam Hopkinson Avatar answered Oct 05 '22 04:10

Adam Hopkinson