How Can I Prevent Memory Leaks in IE Mobile?

Posted by Jake Howlett on Stack Overflow See other posts from Stack Overflow or by Jake Howlett
Published on 2009-09-21T12:55:29Z Indexed on 2010/04/18 5:03 UTC
Read the original article Hit count: 531

Filed under:
|
|
|
|

Hi All,

I've written an application for use offline (with Google Gears) on devices using IE Mobile. The devices are experiencing memory leaks at such a rate that the device becomes unusable over time.

The problem page fetches entries from the local Gears database and renders a table of each entry with a link in the last column of each row to open the entry ( the link is just onclick="open('myID')" ). When they've done with the entry they return to the table, which is RE-rendered. It's the repeated building of this table that appears to be the problem. Mainly the onclick events.

The table is generated in essence like this:

var tmp="";
for (var i=0; i<100; i++){
 tmp+="<tr><td>row "+i+"</td><td><a href=\"#\" id=\"LINK-"+i+"\""+
  " onclick=\"afunction();return false;\">link</a></td></tr>";
}

document.getElementById('view').innerHTML = "<table>"+tmp+"</table>";

I've read up on common causes of memory leaks and tried setting the onclick event for each link to "null" before re-rendering the table but it still seems to leak.

Anybody got any ideas?

In case it matters, the function being called from each link looks like this:

function afunction(){
 document.getElementById('view').style.display="none";
}

Would that constitute a circular reference in any way?

Jake

© Stack Overflow or respective owner

Related posts about ie

Related posts about mobile