Reputation: 2028
Having a problem with the amount of memory being used going up and up, and expanding until there is no memory left. I'm using the GHeat.Net
plugin to build images. Here is the full code:
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 some reason, when I hit the for
loops, the amount of memory used just goes up and up and up, until it hits a ceiling. Even then, the program keeps running, but the amount of memory doesn't go up. The program generates fine at 20Mb, so I can't figure out why it just keeps going up.
I've also tried GC.Collect
at the end of the innermost loop, to no avail. Any ideas?
Upvotes: 1
Views: 460
Reputation: 78155
GHeat.GetTile
returns a Bitmap
which must be disposed.
Also, there's no need to escape paths like that in 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
Upvotes: 4