Visual Basic内存使用量不断扩大

时间:2011-11-22 17:47:01

标签: vb.net memory

在使用的内存量上升和上升时出现问题,并且在没有内存的情况下进行扩展。我正在使用GHeat.Net插件来构建图片。这是完整的代码:

Dim pm As New gheat.PointManager()
Dim g As Graphics

Dim startZoom As Integer = 2
Dim maxZoom As Integer = 17

gheat.Settings.BaseDirectory = "C:\\gheatWeb\\__\\etc\\"

pm.LoadPointsFromFile("C:\\points.txt")

For zoom As Integer = startZoom To maxZoom
    Dim startX As Integer = 0
    Dim startY As Integer = 0
    Dim maxX As Integer = 2 ^ zoom
    Dim maxY As Integer = 2 ^ zoom

    For x As Integer = startX To maxX
        For y As Integer = startY To maxY
            Dim filename As String = "C:\\images\\" + zoom.ToString + "\\x" + x.ToString + "y" + y.ToString + "zoom" + zoom.ToString + ".gif"
            gheat.GHeat.GetTile(pm, "classic", zoom, x, y).Save(filename, System.Drawing.Imaging.ImageFormat.Gif)
        Next
    Next
Next

出于某种原因,当我点击for循环时,使用的内存量会上升和上升,直到达到上限。即使这样,程序仍在运行,但内存量不会增加。该程序在20Mb时生成正常,所以我无法弄清楚为什么它会继续上升。

我还在最里面的循环结束时尝试了GC.Collect,但无济于事。有什么想法吗?

1 个答案:

答案 0 :(得分:4)

GHeat.GetTile返回Bitmap,必须为disposed 此外,没有必要像VB中那样逃避路径。

For x As Integer = startX To maxX
  For y As Integer = startY To maxY
    Dim filename As String = String.Format("C:\images\{0}\x{1}y{2}zoom{3}.gif", zoom, x, y, zoom)
    Using img = gheat.GHeat.GetTile(pm, "classic", zoom, x, y)
      img.Save(filename, System.Drawing.Imaging.ImageFormat.Gif)
    End Using
  Next
Next