代码之家  ›  专栏  ›  技术社区  ›  Jonathan Allen

铁蟒:这会泄露内存吗?

  •  2
  • Jonathan Allen  · 技术社区  · 14 年前

    For Each column In m_Columns
    
         Dim rawValue As String
         rawValue = line.Substring(column.FileColumnIndex.Value - 1, column.FileColumnEndIndex.Value - column.FileColumnIndex.Value + 1)
    
         If column.IncludeColumnFunction <> "" Then
            Dim scope = m_ScriptEngine.CreateScope
            scope.SetVariable("Line", line)
            scope.SetVariable("Row", targetRow)
            If Not CBool(m_ScriptEngine.Execute(column.IncludeColumnFunction, scope)) Then Continue For 'skip this column
        End If
    
        targetRow(column.DatabaseColumnName) = column.ParseValue(rawValue, targetRow)
    Next
    

    名为的字符串column.includeColumn函数从不更改给定列。它通常很简单,比如Row['Foo']=='Bar'。

    我可以/应该缓存已编译的函数吗? 当我处理完scope变量时,是否应该以某种方式销毁它?

    1 回复  |  直到 8 年前
        1
  •  0
  •   JaredPar    14 年前

    在您放在那里的代码示例中没有什么特别突出的。我想说这段代码不太可能是这个问题的起因(尽管需要更多的上下文来确定)。

    对于内存泄漏,通过直接调查问题而不是深入研究代码,可以更快地找到问题。直接调查通常会很快告诉你什么是泄漏的,一旦你知道是什么泄漏,你就可以开始调查管理这类对象的代码。

    有很多工具和文章可以帮助跟踪.Net中的内存问题。这是一个特别好的。