late binding

A

andreas

Thanks David for your explanation, I hope others people agree because the
keywords close, dispose, finalyse, nothing were a litle confusing to me
(and so are sometimes the articles)

David Anton said:
Another way to explain the futility of the original "ob = Nothing" is that
all you are doing anytime you set an object to Nothing is telling the
compiler that "I'm done with this reference". Why would you need to state
this for a local or parameter as the last line of a short-lived routine?
It's an example of coding by rote - not understanding the purpose of the
statement.
It was necessary I think during the pre-SP1 phase of VB4 - there was a bug
which prevented the cleanup of local objects when going out of scope, but
that's ancient history.
--
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



Michel Posseth said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top