in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

This Blog

Syndication

Mirrored Blogs

Ajax Memory Leaks Explained

Douglas Crawford has a great site about JavaScript (the world's most misunderstood, yet most popular, programming language) where he explains memory leaks. If you create HTML through script (as is typical with AJAX applications)-- your application *has* memory leaks in IE if you have click events in the HTML and you don't remove them. Check out his article on memory leaks which include sample demo pages. The leak is only a factor for IE users-- and yes, it's an issue in IE7/8.

To clean up the memory leak bug, you MUST purge the DOM elements of functions before removing them from the DOM. Here's a code sample, gratuitously stolen borrowed from Douglas himself:

////From crockford.com:
function purge(d) {
var a = d.attributes, i, l, n;
if (a) {
l = a.length;
for (i = 0; i < l; i += 1) {
n = aIdea.name;
if (typeof dNo === 'function') {
dNo = null;
}
}
}
a = d.childNodes;
if (a) {
l = a.length;
for (i = 0; i < l; i += 1) {
purge(d.childNodesIdea);
}
}
}

 

 

If you're an AJAX developer, I highly recommend reading through his site. Especially his notes on object orientation, inheritance and the JavaScript language.

Read the complete post at http://feeds.feedburner.com/~r/daniellarson/~3/266462842/cns!D3543C5837291E93!1790.entry


Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts