views:

62

answers:

2

I have a table of frequently updated information. This is presented using a container div with a div for each row, each row containing 10 divs.

I am using setInterval to call a an asmx webservice that returns some json formatted information.

On the success callback I call $("#myContainer").empty(); on the container div and recreate the rows and 10 nested divs for each row's columns.

This page may be left to run for a whole day, so I am wary of updating the DOM like this as I have noticed that memory does rise for the browser over time (IE8).

The other approach I am considering is to add an idea to the row div. When new results process each item of data, look for the corresponding row, if it exists overwrite the data in each div. If it doesn't exist (new data for example), append the row.

What approaches have others used for this sort of long lived pseudo realtime information display.

TIA

+3  A: 

In general, a very safe way to prevent memory leaks is to refrain from destroying and re-creating DOM elements. In situations such as yours, I always try to keep the initial DOM structure, and simply update the inner text of the elements when fresh data from AJAX requests is available.

Daniel Vassallo
Is that a proven fact? Do you have a reference, not that I doubt you, it would be really nice to read about it more.
Raveren
@Raveren: No it is not a proven fact. Actually it is quite a pessimistic approach, as I am sure that modern browsers are more than capable of managing the memory when creating/dropping DOM elements. Nevertheless, finding memory leaks in long-lived web applications (those left open for several days) is such a headache, that I always try to stick to this pessimistic approach. Obviously this would not be possible for complex GMail-style applications. But it looks like the OP is simply keeping a data table updated in realtime, in which case, I would try the approach I suggested first.
Daniel Vassallo
+1  A: 

Refresh the page once in a while.

Sjoerd