close dispose nothing

  • Thread starter Thread starter andreas
  • Start date Start date
A

andreas

Can someone tell me
1)
Is there a difference between closing or disposing a reference data type

2)
about nothing

dim fr as form2
isnothing(fr) gives true

but

dim fr as form2
fr = new form2
fr.dispose
isnothing(fr) gives false

what means nothing?
 
andreas said:
Can someone tell me
1)
Is there a difference between closing or disposing a reference data
type

Closing is not a default pattern. Disposing is, and it's described in the
Framework docs. Some classes might have a Close method, some are disposable,
some have both. Whether closing is the same as disposing depends on the
class. Look at the docs of the class. There is no general answer.
2)
about nothing

dim fr as form2
isnothing(fr) gives true

but

dim fr as form2
fr = new form2
fr.dispose
isnothing(fr) gives false

what means nothing?


Nothing means "no reference". A variable declared As Object or As a
reference type (classes are reference types), are pointers to an object. A
pointer is the address of the object in memory. If the variable is 0, it is
Nothing.

To compare reference, use the Is operator:

If a Is b Then 'True if both variables reference the same object

If a Is Nothing Then True if variable a is Nothing

Don't use the "IsNothing" function. Use the Is operator as shown because it
directly does what has to be done. The IsNothing function does the same, but
there's no need to call a function for this.

In your first example, "fr" is Nothing because you didn't assign anything,
so it's nothing if you check it. In the 2nd example, you assigned the
reference to an object (of type Form2), so it's not Nothing.


Armin
 
Can someone tell me
1)
Is there a difference between closing or disposing a reference data type

2)
about nothing

dim fr as form2
isnothing(fr) gives true

but

dim fr as form2
fr = new form2
fr.dispose
isnothing(fr) gives false

what means nothing?

I would like add 1 more point to the other posters reply that when you
dispose an object, .Net framework says that is does not guarantee the
time of actual disposal.
This is so because the garbage collector runs randomly and is invoked
automatically when Memory is low.
 
andreas said:
1)
Is there a difference between closing or disposing a reference data type

Depends entirely on the class.
Some classes (like StreamReader) do the Dispose automatically when you
call Close; others don't. You just have to read the documentation and
see which one(s) you still need to call Dispose on.
2)
about nothing

dim fr as form2
isnothing(fr) gives true

Create a variable to hold a "form2" object, but do not assign it any
value. That's Nothing.
but

dim fr as form2
fr = new form2
fr.dispose
isnothing(fr) gives false

Create a variable, assign it a reference to a Form2 object, then Dispose
that object. The /reference/ is still perfectly valid (not Nothing),
but the /object/ is Disposed and you'll get errors if you try to access
its properties. Also, the object /won't/ be Garbage Collected because
you still have a reference to it.

HTH,
Phill W.
 
Armin,

As I have the idea that by instance in AdoNet is the closde overriden by the
dispose, while the dispose is overridden with the close.

I think that it is at most places as it is about data.

Cor
 
Andreas,

I would ask this question in particular in the situation of the form in this
way.

Why is there a difference between IsNothing and IsDisposed.

While I write this you see probably already that there is a difference.

A form which IsNothing is has no reference anymore and a form which
IsDisposed does not exist anymore.

However it is cullprit, by just creating your form everytime New you are
maybe using some more nanoseconds, then the test you need if it still exist,
by showing it there will be used billions times more.

However you could have asked what is the difference between a String which
Is Nothing and a string which = Nothing.

The first is not instanced, while the second is empty. However, the second
instances direct the string and therefore it could have been before as well
a string which was not instances. (Because this is always Armins
speciallity: Correct me if I wrote this wrong Armin?)

Cor
 
Cor Ligthert said:
(Because this is
always Armins
speciallity: Correct me if I wrote this wrong Armin?)

I must correct you if you say that my speciality is always
to correct you. ;-)

(I can not contribute anything to the topic because I'm not sure what you
meant with your post)


Armin
 
Andreas,

I would ask this question in particular in the situation of the form in this
way.

Why is there a difference between IsNothing and IsDisposed.

While I write this you see probably already that there is a difference.

A form which IsNothing is has no reference anymore and a form which
IsDisposed does not exist anymore.

I haved to disagree with this. I don't see how it makes any sense to
say "a form which Isnothing". A reference can be Nothing, but not a
form.

A form which has been disposed but not yet garbage collected does
exist, perhaps not visually but certainly it exists as a structure in
memory.
However it is cullprit, by just creating your form everytime New you are
maybe using some more nanoseconds, then the test you need if it still exist,
by showing it there will be used billions times more.

However you could have asked what is the difference between a String which
Is Nothing and a string which = Nothing.

The first is not instanced, while the second is empty. However, the second
instances direct the string and therefore it could have been before as well
a string which was not instances. (Because this is always Armins
speciallity: Correct me if I wrote this wrong Armin?)

I don't really understand what you are saying here, but it sounds
wrong to me. A reference to a string can be Nothing, in which case
there is no memory allocated for the string, or it can point to an
empty string, in which case there is memory allocated. To me "a
String which is Nothing", while worded oddly (because a string can not
be Nothing but a reference to a string can be) to me means a reference
is Nothing. "a string which = Nothing" also doesn't have much meaning
because a string can not be Nothing, only a reference to a string.

There is the oddity with the String class that lets a reference to a
string that contains Nothing be compared to an empty string without
trapping, but I don't think you are talking about that.
 
Back
Top