View Full Version : memory leak??

07-26-2010, 08:37 AM
Hi everyone,

Really hoping someone can help me with a javascript / memory problem I'm having.

Environment is Win7, MSIE v8.0.

I have a pretty simple test function for this problem:

function go() {

// create giant text string in variable 'bill' then set 'bill' to null - store inside variable called 'test' as text.
var test = "bill = 'blah blah blah blah blah (repeat blah about a thousand times or so for file size)'; bill = null;";

// execute text inside variable 'test' as code
var tester = new Function(test);

// destroy function used to execute string as code
tester = null;


now, when you trigger the function go() through a button (ie <button onclick='go();'>go</button>) you can watch the memory usage in taskmgr go up every time you click the button (for me it goes up about 3MB every time go() is called - but that will depend on how many blah's you have).

I have tried replacing var tester = new Function(test); with the eval() command... Same problem.

It would appear the function is creating (storing in memory) a new instance every time its called ... What am I doing wrong here?? How do I stop the memory increasing every time i try to execute the string 'test' as script?

Checked this code in Chrome and Firefox - they don't seem to have any memory issues running this code - its only a IE issue (*sigh*). That doesnt help me as the problem relates to a client's HTA application (can't switch off IE engine).

Huge thanks in advance!

Philip M
07-26-2010, 08:43 AM
Have a look at


It is your responsibility to die() if necessary….. - PHP Manual