Uses jQuery.data () for an element, and then deletes the element through direct memory DOM manipulation

I am working on a site that was written using Prototype, but we will gradually change it to jQuery. Many page updates are done through the Ajax.Updater prototype. However, sometimes the elements that Prototype removes and replaces, run the jQuery widget on them, so $ .cache has links to additional elements created by widgets. Since jQuery does not delete the DOM, it has no way to clear the data from $ .cache for these elements when they are deleted, and I get a memory leak. Is there a way to tell jQuery to check its .cache and discard any data for elements that are no longer in the DOM?

+5
source share
1 answer

It sounds a little complicated - especially since Ajax.Updater is a specialization of Ajax.Request that does not have an onsuccess / oncomplete callback, which means that you may have to periodically cache in periodic mode. This sounds more than creating jQuery 'updater'.

If you want to replace the update with jQuery rewrite, this problem will completely disappear and certainly easier than working around it. A simple "updater" in jQuery follows.

function update() {
    $.ajax({
        type: 'get',
        url: 'theContent.html',
        success: function(text) {
            // .html calls '.cleanData()' internally. No need to do anything else.
            $('#updateMe').html(text);
        }
    });
}

var i = setInterval(update, 5000);
+3
source

All Articles