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. Neccessary to call DISPOSE?

Neccessary to call DISPOSE?

Scheduled Pinned Locked Moved Visual Basic
performancehelpquestion
2 Posts 2 Posters 0 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.
  • C Offline
    C Offline
    cnurse
    wrote on last edited by
    #1

    I declare a brush... Dim lBrush as SolidBrush Then I use it lots of times in a function for different things like gradient fills. So I might do... lBrush = new GradientBrush... Then again... lBrush = new GradientBrush... You get the idea. Should I call lBrush.Dispose before I say lBrush=New brush.... If I don't, do I get a memory leak? Sounds like a waste of time, unless you have an object that is going to be in scope for a long time using transient resources that should be released quickly. Thanks 4 ur help guys. Nursey

    C 1 Reply Last reply
    0
    • C cnurse

      I declare a brush... Dim lBrush as SolidBrush Then I use it lots of times in a function for different things like gradient fills. So I might do... lBrush = new GradientBrush... Then again... lBrush = new GradientBrush... You get the idea. Should I call lBrush.Dispose before I say lBrush=New brush.... If I don't, do I get a memory leak? Sounds like a waste of time, unless you have an object that is going to be in scope for a long time using transient resources that should be released quickly. Thanks 4 ur help guys. Nursey

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      The general rule is yes, of course. Objects that expose the IDisposable interface do so because they contain resources that a limited in some way. The destructor/finaliser of these objects will call Dispose anyway, but is it better to call Dispose when you know you don't need the object any more. Why? Because you don't know when the garbage collector will clean up after you, which could mean that you run out of the resource and are then left wondering why your program failed. So... If its got an IDisposable interface then use it. --Colin Mackay--

      "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

      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