4

Halo All, I'm new to javascript and Jquery. I'm working on analysing the memory leak of a thick client application running on IE8.

This application uses one HTML with multiple javascript pages. I checked the application and found that the variables created in some pages are still alive even after the call of destroy function.

I want to write a generic function to kill all global variables that were not destroyed in the destroy function.

Can someone please help me with this? Also, let me know the techniques to reduce memory leakage.

Many thanks in advance

Subash
  • 119
  • 7
  • 1
    This might help http://stackoverflow.com/questions/2226007/fetching-all-javascript-global-variables-in-a-page or http://stackoverflow.com/questions/8369338/javascript-dumping-all-global-variables – bitkot Jun 04 '13 at 10:54

1 Answers1

3

Created this jsFiddle. Essentially based around the following:

for (x in window) {
    delete window[x];
}

Obviously with a bit more involved, but that's the core.

Tested in Chrome. Should work elsewhere.

Chad Schouggins
  • 3,440
  • 2
  • 23
  • 29
  • Chad - Many thanks for your help... It helped me to destroy all the global variables. I read on the internet that Closures might be one of the major reasons for memory leakage. Can someone kindly let me know if it is necessary to kill all the local variables. – Subash Jun 06 '13 at 05:28