Javascript Leak setting style.backgroundImage

F

fehays

Hello,

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

var newimage = "url(images/" + res.value.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.Image + ")";
if( imagetd.style.backgroundImage != newimage )
{
//imagetd.style.backgroundImage = "";
//imagetd.style.backgroundImage = newimage;
}

Any help would be greatly appreciated.

Thanks
 
V

VK

fehays said:
Hello,

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

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


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

VK

fehays said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top