:: Forum >>

grid leaks memory in AW.all

There seems to be a memory leak in the AW.all array caused by adding and removing grid objects dynamically. For each grid object I create, an entry is added to AW.all. To remove that entry when I remove the grid from the DOM, I call

delete AW.all[id];

where 'id' is the id of my grid. However, there seem to be other <span> objects in AW.all that belong to the deleted grid, all with IDs of "awNN". For example:

AW.all['aw95'] = <span id="grid25-cell-4-14" class="aw-item-template aw-templates-cell aw-grid-cell...

The $owner field of this <span> object points back to my grid object (id = "grid25"), so my grid objects are never released. This leaks a lot of memory.

The pattern in the AW.all array is always like this:
AW.all['aw90]'= = null;
AW.all['aw91]'= = <span ...
AW.all['aw92]'= = null;
AW.all['aw93]'= = <span ...

... etc. And the <span> is always for the last cell in one of my deleted tables.

Is there something else I should be doing when I remove the grid from the DOM, so that all references to it are removed from the AW.all array?

Would this work?
AW.all = {id:0};
It seems extreme and I don't know if its safe.

I'm using AW 2.5.5.
CK
Thursday, September 2, 2010
http://www.activewidgets.com/javascript.forum.25145.2/clear-aw-controls-from-container.html
Friday, September 3, 2010
> /javascript.forum.25145.2/clear-aw-controls-from-container.html

I'm aware of that. If you look at my post, you'll see that I am deleting the grid's entry in AW.all. The problem is that there are other entries in AW.all with id = "awNN" that seem to be leftover <span>'s from the creation of the grid.
CK
Friday, September 3, 2010
I guess it happens when you set different templates for the grid cells and it looks like a bug in AW. I would suggest cleaning bad references with this code -

function removeRefs(){

    var i, r = AW.all;

    for (i in r){
        if (typeof(r[i])=='object' && !document.getElementById(i)){
            delete r[i];
        }
    }
}
Alex (ActiveWidgets)
Friday, September 3, 2010
Below is the code I'm using to prevent the leak. I don't think that my application should be responsible for the cleanup that is done by the code following the "delete other stuff..." comment. But without it, there is a big leak.

function cleanup_AW_all (gridToDelete)
{
    var gid = gridToDelete.getId();
    if (!AW.all[gid])
        return;

    delete AW.all[gid];

    // delete other stuff for the grid stored in AW.all
    for (var awid in AW.all) {
        var obj = AW.all[awid];
        if (obj && obj.$owner == gridToDelete)
            delete AW.all[awid];
    }
}

CK
Friday, September 3, 2010
Thanks Alex. (I think our last posts overlapped). It looks like we came up with similar fixes. Maybe you could add this to your bug list to be fixed in a future release.
CK
Friday, September 3, 2010

This topic is archived.


Back to support forum

Forum search