JavaScript内存泄漏 - 无法弄清楚如何清除变量

时间:2013-05-24 17:30:42

标签: javascript performance

posted a question如何调试内存泄漏,现在我发现了导致内存泄漏的问题。

this.hover.click(function() {
        hover.click();
    });

    this.click = function(display, section) {
    if(this.expanded() == true) {
        this.collapse();
        DrillDown.remove(true);
        Table.isSortable = true;
        if(Focus.Focus != null)
            {
                Focus.Focus.ClearFocus();
            }
    }
    else {
        this.expand();
        Table.hideRowHovers(this.person);
        DrillDown.display(this.Row.Cell, this.person, display, section);
        Table.isSortable = true
        if(Focus.Focus != null)
        {
            Focus.personFocus.SetFocus(this.person.Id, this.person.Id2, this.person.name);
        }
    }
}

它说hover.click持有对行

中Row对象的引用
DrillDown.display(this.Row.cell, this.person, display, section);
                  ^^^^^^^^^^^^^  

//This is how I am passing the row object
this.hover = new PersonRowHover(this.person);
this.hover.create(this);
this.hover.html = "";

this.hover.create(this)引用我为每个人创建的PersonRow对象。 我试图将其设置为null但它会破坏我的代码。有关如何清除此变量的任何帮助将不胜感激。我试图清除this.Row所以Row对象被垃圾收集。

谢谢

1 个答案:

答案 0 :(得分:0)

您可以尝试更改

DrillDown.display(this.Row.cell, this.person, display, section);

var cell = this.Row.cell;
this.Row.cell = null;
DrillDown.display(cell, this.person, display, section);

如果this.Row没有对cell的任何引用,则应允许Row进行垃圾回收。