Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. When and what do I Dispose when using GDI+

When and what do I Dispose when using GDI+

Scheduled Pinned Locked Moved Visual Basic
graphicswinformsjsonhelpquestion
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rspercy65
    wrote on last edited by
    #1

    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

    E 1 Reply Last reply
    0
    • R rspercy65

      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

      E Offline
      E Offline
      Eslam Afifi
      wrote on last edited by
      #2

      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 the Bitmap and the Graphics objects. You should also read about the Using statement[^].

      Eslam Afifi

      R 1 Reply Last reply
      0
      • E 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 the Bitmap and the Graphics objects. You should also read about the Using statement[^].

        Eslam Afifi

        R Offline
        R Offline
        rspercy65
        wrote on last edited by
        #3

        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

        E 1 Reply Last reply
        0
        • R rspercy65

          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

          E Offline
          E Offline
          Eslam Afifi
          wrote on last edited by
          #4

          You're welcome.

          Eslam Afifi

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups