Hey all,
Curiosity runs wild.
Suppose I have this code...
When I run this and watch memory consumption in the task manager, memory for the app continuously increases until I finally get an ArgumentException from System.Drawing.dll after 14 iterations.VB.net Code:
Do Static count As Integer = 0 Me.PictureBox1.Image = New Bitmap(5000, 5000) count += 1 Debug.Print(count) 'breathe Threading.Thread.Sleep(10000) Loop
If however I add a GC.Collect to the code, memory stays in check and it will continue to run...
It was my understanding the the CLR will collect the garbage as needed, so what gives? Why do I need to manually collect garbage for this to work?vb.net Code:
Do Static count As Integer = 0 Me.PictureBox1.Image = New Bitmap(5000, 5000) GC.Collect()' <---- Adding this allows the loop to run indefinitely count += 1 Debug.Print(count) 'breathe Threading.Thread.Sleep(10000) Loop




Reply With Quote