L
Lloyd Sheen
Tom Shelton said:Calling dispose, sure - set to nothing no. If it's a local resource.
IMHO,
you should always call dispose if it is implemented.
I only mean Nothing (null) from a memory managment perspective - there are
definate algorthmic situations where setting an object to nothing makes
sense.
I'm only refering to the setting of nothing in regards to memory
managment.
The runtime is smart enough to know if a local object is not read again
during
a methods execution, then it is safe to clean it up.
Absolutely true... The 1% is basically, for logic and non local
resources.
From a memory management perspective, a local variable never has to be set
to
nothing for the GC to do it's job - though I still recommend calling
dispose
when an object implements IDisposable...
I have been following this and think I have found a situation where settinga
variable to nothing is required. I am using the datarepeater (winforms)
from MS and one of the controls in the template is a picturebox. In an
attempt to get memory consumption under control I am getting the binding
list for the datarepeater and if it is already set I go thru the items
disposing the image for the picturebox (it will be in a list of objects).
Now if I get the objects again (using Linq which will cache them) and the
image has been disposed, there is no IsDisposed that I can get VB to
understand for the image so I had to do a dummy attempt to get a property
from the image which if it failed meant that the image was disposed. By
setting the image to nothing that makes for a much simpler , faster since it
has no try / catch to indicate the dispose.
LS