Re: How to clear controls from a form - Help Needed



Jack,

This is where my VB6 roots probably show. I always treat = (equals) as
meaning copy from the right side to the left side. From what you have just
said that isn't the case, in this instance I am making my variable on the
left side actually equal to rather than assigning.

Now I understand that, I can see that if I dispose (or destruct if you
believe what Cor says), the variable on the left side of the argument, I am
also disposing the original one as they are one and the same object.

That actually makes me a lot happier. Also knowing that as soon as I exit
the black box function that reference is removed helps. I feel a lot tidier
knowing that.

Thanks for you help.

Siv


--
Martley, Near Worcester, UK


"Jack Jackson" wrote:

On Thu, 7 Aug 2008 12:52:01 -0700, Siv <Siv@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:

Jack,
I am pleased to report that in pretty much ebery instance the calling
routine will have something like this:

Dim CallersDR as sqlDataReader=nothing

try
CallersDR = GetData(SomeID)

...
various code that uses the CallersDR.
...

Catch ex as exception
Error handler code
Finally
if not isnothing(CallersDR) then
CallersDR.Close()
End If
End Try

So if I read teh conversations correctly, the line:

CallersDR.Close()

Will not only close the CallersDR but will also close the Dr that is in the
black box routine (GetData(ID)) as well? This is the concept that I didn't
follow and what was worrying me because in my mind I see the Dr used in the
GetData as being a separate object to the one in the above calling routine.
So therefore I have been worrying that this was being left undisposed.

Am I right in surmising from what has been said above that the Dr in GetData
and teh CallersDR in my calling routine are both referencing the same
DataReader object from the moment that the GetData routine returns the Dr it
has to the caller??

If this is correct I will be a happy man as this has clarified something I
have not understood properly.

Siv

There is no "Dr that is in the black box routine (GetData(ID)) as
well". There is only one SqlDataReader. The black box method creates
it and returns a reference to it. The reference that the black box
method holds to the object goes away once the method exits, leaving
only the caller's reference.

It's like this:

Dim dr As New SqlDataReader
Dim dr1 As SqlDataReader = dr
Dim dr2 As SqlDataReader = dr

There is only one object with three references to that object: dr, dr1
and dr2.

.



Relevant Pages

  • Re: How to clear controls from a form - Help Needed
    ... CallersDR = GetData ... black box routine ) as well? ... it and returns a reference to it. ... Dim dr As New SqlDataReader ...
    (microsoft.public.dotnet.languages.vb)
  • Re: to dispose or not ?
    ... If I use GC.KeepAlive(obj) where I would have used obj = nothing what is the cost vs the risk of not ... When writing an IDisposable routine or Finalizer routine, you must do a lot of extra checks to avoid the problem of the GC running the Dispose and/or Finalizer routines in seemingly random order. ... setting the reference to nothing reduces the reference count to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How should an exit routine wait for release() callbacks?
    ... module's exit routine has to wait until the releaseroutine for that ... The module has now given up any reference to the device it ... reference to it and its release routine gets passed to the driver core. ... subsystem can't be unloaded without unloading my driver first. ...
    (Linux-Kernel)
  • Re: Larry Wall, on Tcl
    ... In Tcl, objects ... that no other object can reference this object without trying ... At this point the GC routine ... failure and make a decision on what needs to be done upon failure. ...
    (comp.lang.tcl)
  • Re: Using with
    ... It was a fair test, both routines use the exact same variable reference, ... still, using your change, I again find using With to be the faster method. ... routine, that was by design. ...
    (microsoft.public.vb.general.discussion)

Loading