Javascript memory leak on page refresh; to fix?

I experience a memory leak in IE that occurs when the page is refreshed (as I described in this in the SO post).

All I want to know at this stage is : is there a way to β€œunload” a document (which can be called when the page is refreshed or closes) for the event to clear ALL? I am looking for a simple solution that will ensure that everything is destroyed to avoid leakage. Is this possible, or should I continue to study the details of the leak and fix it on the object by object?

Refresh . I may not be descriptive enough. I can’t (at least I don’t think I can) just set all my objects to null: I have event handlers for click events, etc. Therefore, the application must constantly β€œlive” until it is closed . Also, if I then think about simply zeroing out everything in the "unload" method (called when the page exits), then should all of my objects have a global scope (on the right)? What is the best way to fix this? Is there a way to get a list of all reference objects so that I can reset them? Do I have to add every object that I use for an array in order to dereference it later?

+3
source share
3 answers

try window.onbeforeunload or window.onunload and set the variables you use for null. or are you looking for something else?

+1
source

Set your objects to zero and they will not be skipped.

+1
source

check if you use a random anti-cache url parameter, this may lead to memory leaks

  • IE tries to keep all scripts loaded from the same domain in memory when you move from page to page, because there is a high probability that you will need almost the same scripts on different pages.
  • the random anti-cache parameter added to the script url makes it another script (at least caching is tricked by this)
  • since we know that IE is trying to download all possible scripts for the domain and save them
  • random anti-cache settings lead to a memory leak, because every time otherwise the same scripts have a different URL, and IE considers them to be different, and loads them again and again every time they reboot and saves them in mind.
0
source

All Articles