Michel,
If the method from objvar.PerformsomeAction is calling the GC or by
instance do a show of whatever, than it works in my opinion.
Cor
"m.posseth" <
[email protected]> schreef in bericht
Cor ,
AFAIK does the GC not start in the middle of a routine.
well i wonder if it doesn`t ,,, ,, cause
this code
sub DoSomeStuff ()
Dim objVar as new foo
for i as integer = 1 to 1000
if i <= 50 then
objvar.PerformsomeAction
if i=50 then objVar = Nothing
else
'do something else except using ObjVar
end if
next
End Sub
Can be found in the best practices guidelines from MS
So i guess the reasson is that objVar can be released before it runs
out of scope ( before the method ends ) otherwise some writers at MS
made some serious flaws in there documentation
regards
Michel Posseth [MCP]
Michel,
I answer your question in your other reply here. AFAIK does the GC not
start in the middle of a routine. That is AFAIK the only reason to
start the GC by hand. This with as exception that the action in your
sample is a kind of IO operation (including painting). Than I agree
that it can be a reason to do as you show, however, than I would set
in your sample the force of the GC. I did not see now that you did
mean an IO (or operation as that).
Cor
"Michel Posseth [MCP]" <
[email protected]> schreef in bericht
Well ......
It also doesn`t hurt , to use Nothing , and in a lot of MS examples
i see Nothing used even better i found some articles that state that
in some situations it might even benefit the GC to use Nothing .
Can you clean to good in your home ???
and indeed as a VB6 progger i learned how to clean up my mess ....
in the example i showed in a above post for instance it is in my
opinion perfectly valid to use Nothing , as it might help in the
release of the object before the method has finished
regards
Michel Posseth [MCP]
"David Anton" <
[email protected]> schreef in
bericht As Herfried says, it's pointless to set ob to Nothing - ob is just a
parameter that goes out of scope immediately after you are setting
it to
Nothing, so that's unnecessary. Excessive setting objects to
Nothing is a
holdover from classic VB (and even there it's not required as much
as people
think). Also, setting it Nothing in that method does not remove the
reference in the calling method - but even there it's not practical
unless
your calling method is so long that you're worried about encouraging
garbage
collection as soon as possible (even then, "Using" is a more direct
approach
if that's your concern).
So, all you're left with in your function is:
if not (ob is nothing) then
ob.close
I think just using the Close methods on the objects directly from
your
calling method is cleaner.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
:
Hi,
I am working with the streams objects
(filestream,streamwriter,streamreader)
May I do or is it good programming to make a sub like :
public sub Closestreams(ByRef ob as object)
if not (ob is nothing) then
ob.close
ob = nothing
end if
end sub
thanks for any response