Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the most memory leak safe approach

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 id 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

like image 989
MattC Avatar asked Apr 09 '10 11:04

MattC


People also ask

Which method is used to detect memory leak?

Using Memory Profilers Memory profilers are tools that can monitor memory usage and help detect memory leaks in an application. Profilers can also help with analyzing how resources are allocated within an application, for example how much memory and CPU time is being used by each method.

How would you prevent a memory leak?

To avoid memory leaks, memory allocated on heap should always be freed when no longer needed.

What is the best tool to detect memory leaks?

To find memory leaks and inefficient memory usage, you can use tools such as the debugger-integrated Memory Usage diagnostic tool or tools in the Performance Profiler such as the . NET Object Allocation tool and the post-mortem Memory Usage tool.

What is the main cause of memory leaks?

DEFINITION A memory leak is the gradual deterioration of system performance that occurs over time as the result of the fragmentation of a computer's RAM due to poorly designed or programmed applications that fail to free up memory segments when they are no longer needed.


1 Answers

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.

like image 59
Daniel Vassallo Avatar answered Sep 27 '22 17:09

Daniel Vassallo