Drag and Drop Memory Issue

View: New views
1 Messages — Rating Filter:   Alert me  

Drag and Drop Memory Issue

by scintillus () :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm having an issue with Drag and Drop memory / cpu consumption which may be a result of the way I refresh my DOM elements.  Hopefully someone has done the following before and knows where I'm going wrong.  What I do is send my javascript a set of html to inject (from my servlet), which includes divs of a class that I turn into Draggables (and droppables) after injecting.  I don't explicitly destroy the old draggables, and I think that when I overwrite the DOM elements through this injection, they are somehow kept around by mochikit.  Perhaps what I should do is find these old draggables before injecting, delete them, then do as I do?  Here is some code to illustrate :

retrievePresentation: function(result)
{
    //load the elements from the server to the html
    var response = result.responseXML.documentElement;
    var content="";
    for( var i=0; i<response.getElementsByTagName("contents")[0].childNodes.length; i++ ) {
        content += response.getElementsByTagName("contents")[0].childNodes[i].data;
    }
    var destination = response.getElementsByTagName("destination")[0].firstChild.data;
    var drag_class  = response.getElementsByTagName("draggable_class")[0].firstChild.data;
    var drop_class  = response.getElementsByTagName("droppable_class")[0].firstChild.data;
    var presentationArea = document.getElementById(destination);
    presentationArea.innerHTML=content;
    //set up draggability if applicable
    if( drag_class != "none" ) {
               
        var allDraggablesArray = MochiKit.DOM.getElementsByTagAndClassName('*', drag_class);
        for(var aDraggable in allDraggablesArray) {
                               
            var widId = allDraggablesArray[aDraggable].id;
            new MochiKit.DragAndDrop.Draggable(widId);
        }
        if( drop_class != "none" ) {
                       
            var allDroppablesArray = MochiKit.DOM.getElementsByTagAndClassName('*', drop_class);
            for(var aDroppable in allDroppablesArray) {
                                       
                var widId = allDroppablesArray[aDroppable].id;
                new MochiKit.DragAndDrop.Droppable(widId, { ondrop: MochiKit.Base.bind(this.onDrop, this)});
            }
        }
    }
}

Thanks for reading!