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