473,842 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dispose Again!

Ok, I'm trying to dispose of every object that I create that has a dispose
method based on advice from this newsgroup. However, I'm not sure how to
dispose of the following object that was created inside a method call.

dim myvar as new object1
object1.dosomet hingmethod(new object2)

Note that object 2 has a dispose method but how do I dispose of it unless I
do the following:

dim myvar as new object1
dim mydisposableobj ect as new object 2
object1.dosomet hingmethod(mydi sposableobject )
myotherobject.D ispose
--
Dennis in Houston
Nov 21 '05
156 5939
Thanks to all. I am beginning to understand a little of what the dispose is
all about and all this discussion certainly helps me and I think a lot of
people using VB.Net. I have implemented the practice of "If it's got a
dispose method, then call it when I'm thru with it and if it doesn't have a
dispose method, don't worry about it!"

"Cor Ligthert" wrote:
Dennis,

When you inherit from Components than there is already Idispose implemented
in the base class. (By instance all classes in Sytem.Data and
System.Windows. Forms.Control inherit from Components) You just have to do
nothing because it is done by the base class when that class goes out of
scope. Therefore I inherit from components when I make a class from which I
have slightly the idea that it has unmanaged resources in it.

http://search.microsoft.com/search/r...&c=0&s=1&swc=0

IComponent implements IDisposable for when you are searching that.

I hope this helps,

Cor

Nov 21 '05 #21
Dennis,
Thanks to all. I am beginning to understand a little of what the dispose
is
all about and all this discussion certainly helps me and I think a lot of
people using VB.Net. I have implemented the practice of "If it's got a
dispose method, then call it when I'm thru with it and if it doesn't have
a
dispose method, don't worry about it!"

While that is in my opinion not the good method. It is in a lot of cases
exactly opostite, when it has no dispose method, create it when it is using
an unmanaged resource.

When you read my message than you see that a lot of classes have dispose,
just because they inherits form component. That is not a reason to call all
the members in that which have that as well all individual.

Cor
Nov 21 '05 #22
Dennis,
Thanks to all. I am beginning to understand a little of what the dispose
is
all about and all this discussion certainly helps me and I think a lot of
people using VB.Net. I have implemented the practice of "If it's got a
dispose method, then call it when I'm thru with it and if it doesn't have
a
dispose method, don't worry about it!"

While that is in my opinion not the good method. It is in a lot of cases
exactly opostite, when it has no dispose method, create it when it is using
an unmanaged resource.

When you read my message than you see that a lot of classes have dispose,
just because they inherits form component. That is not a reason to call all
the members in that which have that as well all individual.

Cor
Nov 21 '05 #23
How am I to know if objects such as OleDbDataAdapto r use unmanaged resources
and whether or not I should call it's dispose method?

"Cor Ligthert" wrote:
Dennis,
Thanks to all. I am beginning to understand a little of what the dispose
is
all about and all this discussion certainly helps me and I think a lot of
people using VB.Net. I have implemented the practice of "If it's got a
dispose method, then call it when I'm thru with it and if it doesn't have
a
dispose method, don't worry about it!"

While that is in my opinion not the good method. It is in a lot of cases
exactly opostite, when it has no dispose method, create it when it is using
an unmanaged resource.

When you read my message than you see that a lot of classes have dispose,
just because they inherits form component. That is not a reason to call all
the members in that which have that as well all individual.

Cor

Nov 21 '05 #24
How am I to know if objects such as OleDbDataAdapto r use unmanaged resources
and whether or not I should call it's dispose method?

"Cor Ligthert" wrote:
Dennis,
Thanks to all. I am beginning to understand a little of what the dispose
is
all about and all this discussion certainly helps me and I think a lot of
people using VB.Net. I have implemented the practice of "If it's got a
dispose method, then call it when I'm thru with it and if it doesn't have
a
dispose method, don't worry about it!"

While that is in my opinion not the good method. It is in a lot of cases
exactly opostite, when it has no dispose method, create it when it is using
an unmanaged resource.

When you read my message than you see that a lot of classes have dispose,
just because they inherits form component. That is not a reason to call all
the members in that which have that as well all individual.

Cor

Nov 21 '05 #25
Generally, you can look a the big picture of what the class does. With any
of the data connectivity classes (dataadapters, datareaders, connections),
calling dispose is a good idea because the basic job of these classes is to
connect to unmanaged resources.

Classes that help you get to resources "outside" of the CLR's domain are
good classes to dispose. But I wouldn't worry about disposing a label, for
example.
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:F4******** *************** ***********@mic rosoft.com...
How am I to know if objects such as OleDbDataAdapto r use unmanaged
resources
and whether or not I should call it's dispose method?

"Cor Ligthert" wrote:
Dennis,
> Thanks to all. I am beginning to understand a little of what the
> dispose
> is
> all about and all this discussion certainly helps me and I think a lot
> of
> people using VB.Net. I have implemented the practice of "If it's got a
> dispose method, then call it when I'm thru with it and if it doesn't
> have
> a
> dispose method, don't worry about it!"
>

While that is in my opinion not the good method. It is in a lot of cases
exactly opostite, when it has no dispose method, create it when it is
using
an unmanaged resource.

When you read my message than you see that a lot of classes have dispose,
just because they inherits form component. That is not a reason to call
all
the members in that which have that as well all individual.

Cor

Nov 21 '05 #26
Generally, you can look a the big picture of what the class does. With any
of the data connectivity classes (dataadapters, datareaders, connections),
calling dispose is a good idea because the basic job of these classes is to
connect to unmanaged resources.

Classes that help you get to resources "outside" of the CLR's domain are
good classes to dispose. But I wouldn't worry about disposing a label, for
example.
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:F4******** *************** ***********@mic rosoft.com...
How am I to know if objects such as OleDbDataAdapto r use unmanaged
resources
and whether or not I should call it's dispose method?

"Cor Ligthert" wrote:
Dennis,
> Thanks to all. I am beginning to understand a little of what the
> dispose
> is
> all about and all this discussion certainly helps me and I think a lot
> of
> people using VB.Net. I have implemented the practice of "If it's got a
> dispose method, then call it when I'm thru with it and if it doesn't
> have
> a
> dispose method, don't worry about it!"
>

While that is in my opinion not the good method. It is in a lot of cases
exactly opostite, when it has no dispose method, create it when it is
using
an unmanaged resource.

When you read my message than you see that a lot of classes have dispose,
just because they inherits form component. That is not a reason to call
all
the members in that which have that as well all individual.

Cor

Nov 21 '05 #27
Dennis,

There is no need to dispose any object of system.data.

I have written a while that the exception on this is the connection, that
is used for the connection pooling what was consequently told by Angel in
the AdoNet newsgroup and that was done something with the fysical connection
string (not the code) in a kind of overriden function from dispose.

Because this message below in that newsgroup (it is not the first) I become
confused again however keep that dispose for the connection string. The
other objects does not need a dispose. There the dispose is only because the
method is inherited from components from which all system.data classes
inherits.

http://groups-beta.google.com/group/...11c0671640ad38

I hope this give some idea's

Cor
Nov 21 '05 #28
Dennis,

There is no need to dispose any object of system.data.

I have written a while that the exception on this is the connection, that
is used for the connection pooling what was consequently told by Angel in
the AdoNet newsgroup and that was done something with the fysical connection
string (not the code) in a kind of overriden function from dispose.

Because this message below in that newsgroup (it is not the first) I become
confused again however keep that dispose for the connection string. The
other objects does not need a dispose. There the dispose is only because the
method is inherited from components from which all system.data classes
inherits.

http://groups-beta.google.com/group/...11c0671640ad38

I hope this give some idea's

Cor
Nov 21 '05 #29
I'm not so sure about that Cor. I have read many articles and seen many
posts that suggest that the DataAdapter, DataReader and Connection objects
SHOULD be disposed.
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
Dennis,

There is no need to dispose any object of system.data.

I have written a while that the exception on this is the connection, that
is used for the connection pooling what was consequently told by Angel in
the AdoNet newsgroup and that was done something with the fysical
connection string (not the code) in a kind of overriden function from
dispose.

Because this message below in that newsgroup (it is not the first) I
become confused again however keep that dispose for the connection string.
The other objects does not need a dispose. There the dispose is only
because the method is inherited from components from which all system.data
classes inherits.

http://groups-beta.google.com/group/...11c0671640ad38

I hope this give some idea's

Cor

Nov 21 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.