views:

334

answers:

1

In windows, when an application is minimised the OS frees up memory associated with application by placing the data within a page file. Other garbage collection may also execute.

In the case of internet explorer running my javascript app I find that if the memory usage starts at 60mb then minimising the browser reduces the memory to 17mb. Maximising then takes it back up to 40mb

A 20mb gain.

My application makes heavy use of javascript and I suspect that IE is forcing a garabage collection of the objects which are no longer referenced.

Via javascript (IE only) you can force garbage collection via:

CollectGarbage()

So, if I call this method (without minimising the screen) I only reclaim a meg or 2.

If I call this via the event queue:

setTimeout(CollectGarbage, 1000)

I reclaim around 3 meg

My application is designed to run all day and so memory management is very important.

Anybody got any ideas how to force IE to clean up its memory to the same extent that a manual minise does?

Suggestions of programatically minimising the browser will be scoffed at!

Cheers :)

+1  A: 

Use the delete keyword to undefine the variable/property, saving you memory. More here.

But if you only need to lose a reference to an object property, just set it to null and wait for the next collection.

Be careful using closures and lambda functions, as they have traditionally been memory hogs and sources of leaks. See Understanding and Solving Internet Explorer Leak Patterns.

geowa4
delete removes the property off a prototype and consequently removes the reference..obj.prop = null just removes the reference. So, in the case of delete if you were to iterate over the objs properties, you would find that the number of properties will be reduced.In the case of obj.prop = null, the number of properties remains the same.The difference between these to approaches is not significant from the memory point of view, but they are semantically quite different.
ListenToRick