When and what do I Dispose when using GDI+
-
I would like to know if I need to dispose of anything in this code Dim frmToRnd As System.Windows.Forms.Form = Me Dim regionRects(radius * 2 + 2) As System.Drawing.Rectangle Dim circle As New Bitmap(radius * 2, radius * 2) Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(circle) g.Clear(Color.White) g.FillEllipse(Brushes.Black, 0, 0, circle.Width, circle.Height) The rest of the code just uses what you see above. Do i use Dispose.g or do I need to dispose of regionRect and circle? Thanks in advance for any help, time and patience. rspercy60
rspercy If "You wash your feet and find a pair of socks " Then "You ARE a Redneck" End If
-
I would like to know if I need to dispose of anything in this code Dim frmToRnd As System.Windows.Forms.Form = Me Dim regionRects(radius * 2 + 2) As System.Drawing.Rectangle Dim circle As New Bitmap(radius * 2, radius * 2) Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(circle) g.Clear(Color.White) g.FillEllipse(Brushes.Black, 0, 0, circle.Width, circle.Height) The rest of the code just uses what you see above. Do i use Dispose.g or do I need to dispose of regionRect and circle? Thanks in advance for any help, time and patience. rspercy60
rspercy If "You wash your feet and find a pair of socks " Then "You ARE a Redneck" End If
You should dispose objects that are IDisposable[^] because those objects' classes do implement this interface to provide the method
Dispose
to release unmanaged resources. In your code you should dispose theBitmap
and theGraphics
objects. You should also read about the Using statement[^].Eslam Afifi
-
You should dispose objects that are IDisposable[^] because those objects' classes do implement this interface to provide the method
Dispose
to release unmanaged resources. In your code you should dispose theBitmap
and theGraphics
objects. You should also read about the Using statement[^].Eslam Afifi
-
Thank you very much Eslam. I knew somethings have to be disposed of, but I didnt know what. Once again, Thank You.
rspercy If "You wash your feet and find a pair of socks " Then "You ARE a Redneck" End If
You're welcome.
Eslam Afifi