By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,024 Members | 2,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,024 IT Pros & Developers. It's quick & easy.

Javascript Leak setting style.backgroundImage

P: n/a
Hello,

Can someone please tell me why this code leaks? The handle count for IE
continues to increase.

var newimage = "url(images/" + res.value[i].Image + ")";
if( imagetd.style.backgroundImage != newimage )
{
imagetd.style.backgroundImage = "";
imagetd.style.backgroundImage = newimage;
}
I'm using a setInterval to call the function. If I comment out the
change of the background, i get no leak.

This doesn't leak:

var newimage = "url(images/" + res.value[i].Image + ")";
if( imagetd.style.backgroundImage != newimage )
{
//imagetd.style.backgroundImage = "";
//imagetd.style.backgroundImage = newimage;
}

Any help would be greatly appreciated.

Thanks

Feb 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
VK

fehays wrote:
Hello,

Can someone please tell me why this code leaks? The handle count for IE
continues to increase.

var newimage = "url(images/" + res.value[i].Image + ")";


What are res, value[i] and Image? Are these your custom JavaScript
objects or some are form elements?

Feb 16 '06 #2

P: n/a
Those are custom objects created by the ajax .net dll i'm using.

Feb 16 '06 #3

P: n/a
VK

fehays wrote:
Those are custom objects created by the ajax .net dll i'm using.


Actually all these "script memory leaks" is a new "blame on it" subject
recently :-)
As JavaScript / JScript has an automatic garbage collector schema (like
in Java), there are very few situations where you really can say
"memory leak". Amount of used handles or used memory increase by itself
*doesn't mean anything*. You script may calculate var a = 2+2 and have
99% of allowed memory used. And a minute later it may start calculating
the purpose of this universe and the memory usage will be 1%. It's not
a C-like construct/destruct here ;-)

If some time later you're getting "Out of memory", "Stack overflow" or
your system gets unresponsive, then let's look for a leak.
If nothing of this, then don't bother with system monitoring - it works
in its way and most probably it works just fine.

If your particular situation is bothering you, try to call undocumented
CollectGarbage() method and see (whatever system monitor are you using)
if the number of used handles will drop at least a bit.

If not, let's see where and how are you getting the imagetd reference.

Feb 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.