IronPython:这会泄漏内存吗?

时间:2010-10-14 05:47:00

标签: vb.net memory-leaks ironpython dynamic-language-runtime

我的程序中存在大量内存泄漏。这是我第一次在紧密循环中使用IronPython,所以我想知道这是否是原因。

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.IncludeColumnFunction的字符串永远不会更改给定列。它通常很简单,比如“Row ['Foo'] =='Bar'”。

我可以/应该缓存已编译的函数吗? 当我完成它时,我应该以某种方式破坏范围变量吗?

1 个答案:

答案 0 :(得分:0)

在您提供的代码示例中,没有什么特别突出。我会说这个特定的代码不太可能导致问题(尽管需要更多的上下文来确定)。

如果内存泄漏,您可以通过直接调查问题与挖掘代码来更快地跟踪问题。直接调查通常会很快告诉您什么是泄漏,一旦您知道什么是泄漏,那么您可以开始调查管理该类型对象的代码。

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