View Full Version : Memory Leak issue when using startAutoRefresh

6 Feb 2007, 8:52 PM
Guys & Gals,

I'm trying to create a generic div that refreshes itself, and when you click a link from inside it, it submits to the div rather than reload the page. The div pretty much behaves like an iframe.

The idea is to use the updateManager's on "load" event to attach onclick events to the links inside the loaded div.

So far so good. With Jack's top notch doco, I'd managed to get stuff up and running. Everything seems to work. (see code at bottom)

However, despite taking some advice from http://jibbering.com/faq/faq_notes/closures.html, the code below still leaks memory.

The question is, has anyone tried anything similar? Any thoughts on what could be wrong? Is there any newbie thing I've completely missed out on?

Does 'startAutoRefresh' have some sort of memory footprint?
Does attaching events through addManagedListener cause memory to be leaked?
Any hints on how I'd be able to debug what's in memory?

FYI, by leaking I mean that the memory footprint just keeps on growing (~1.5GB overnight). In an hour, FireFox went from 45MB -> 170MB and IE went from 38MB -> 420MB in half an hour.


Mark C

PS I'm using 0.33 RC3

<div id="latestChanges">
<script type="text/javascript">
function initPortletlatestChanges()
var portlet = getEl('latestChanges');
var updateManager = portlet.getUpdateManager();
updateManager.showLoadIndicator = false;
updateManager.on('update', rewriteFormAndLinks);



YAHOO.util.Event.onAvailable('latestChanges', initPortletlatestChanges);

and the 'rewriteFormAndLinks' looks a bit like:

function ajaxClickHandler(e, updateDivId)

var updater = getEl(updateDivId).getUpdateManager();
var link = e.findTarget('internalLink', 'a');


function rewriteFormAndLinks(el, oResponseObject)
var updater = el.getUpdateManager();
var links = el.getChildrenByClassName('internalLink', 'a');
for (var i = 0; i < links.length; i++)
links[i].addManagedListener('click', ajaxClickHandler, el.id);

6 Feb 2007, 9:10 PM
First, upgrade to the final .33 release - it's possible it's an old bug. Second do a search here for other threads on memory leaks - there was a discussion of this in the past, which may shed some light until somebody else suggests anything.

Are you repeatedly adding listeners to the same link elements? Also, rather than adding listeners to each link, you could just add 1 listener to the containing div and then in the handler determine which link (if any) you're handling.

6 Feb 2007, 9:32 PM
Second do a search here for other threads on memory leaks

I had a read of this this (http://www.yui-ext.com/forum/viewtopic.php?t=237&highlight=leak), but I think the problem here is a little different? That post was more about leaks between page refreshes, whereas mine seems to be an issue of memory use with reloading elements of the page. I don't know if there's an "unload" hook for elements within a window?

Thanks for your suggestions, I'll try and update the libs to the latest version and then try the onclick on the DIV to see if that helps at all.