• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 734
  • Last Modified:

IE javascript memory usage

Load a page with the below code in IE7, the memory usage of the browser shoots up to about 100megs on my system and doesn't reduce down until the page is unloaded.  How do I clean up the memory the unused object is taking up?

In firefox if you try this the memory usage spikes and then a few seconds later reduces down, looks like their garbage collector takes care of it.
<script type="text/javascript">
    var obj = [];
    for (var x = 0; x < 999999; x++) obj[obj.length] = "a";
    obj = null;
    delete obj;
</script>

Open in new window

0
eChalk
Asked:
eChalk
  • 4
  • 3
1 Solution
 
scrathcyboyCommented:
is there a purpose to this 1 million iteration loop?  Or are you just testing to see if javascript can tie up the entire system resources via the browser -- the answer is YES IT CAN !!
0
 
eChalkAuthor Commented:
I have an extremely large page with lots of javascript objects and 3rd party components, and every time i refresh it is not releasing all of it's memory and growing very large in memory usage until the browser is closed.  This is a first step for me to be able to clean up... I'm wondering if in this case there is any way to clear the object from the browser memory without unloading the page.
0
 
Hube02Commented:
IE is known to have memory leaks, however, other browsers will also leak memory to some extent. There are many things that can cause this memory leakage and perhaps the code on your page incorporates some of the know issues.

You could start here: http://www.codeproject.com/KB/scripting/leakpatterns.aspx

Although, if you are using 3rd party components the problems may be difficult to locate. Many developers do not keep the problems in mind and in some cases do not know they are creating a problem. And then again, in some cases, it is not possible to avoid the problem completely.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
scrathcyboyCommented:
"I have an extremely large page with lots of javascript objects and 3rd party components"

OK, the way to debug this is to run firefox, and use tools, error console, and look for any errors.  There are also more elaborate tools like firebug -- www.getfirebug.com/ -- which will tell you where the problems are.  

It would be a first guess to check the 3rd party components, that is what most would say.  But in your case if you are using javascript objects, I think that is the most likely place to look -- these objects will not be being closed correctly, and accumulate in the hundreds or thousands.  Try the debugging tools in firefox.
0
 
eChalkAuthor Commented:
Firefox does not have as bad a leak as IE.  What tools are available in firefox to spot leaks?  I know of this one for IE (best of the ones i looked at): http://blogs.msdn.com/gpde/pages/javascript-memory-leak-detector.aspx
0
 
scrathcyboyCommented:
In FF, there is the built-in error console -- for more elaborate checking of objects not being closed, try their Firebug Plug in --  https://addons.mozilla.org/firefox/addon/1843
0
 
scrathcyboyCommented:
how come the comment 22680912 was not accepted then?
0
 
eChalkAuthor Commented:
Because Firebug doesn't have an in depth memory tracing module.  Once the page unloads, theres no window to go to to see all the stuff still hanging, like the JavaScript Memory Leak Detector for IE.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now