Suppress finalize in dataset constructor???

  • Thread starter Alvin Bruney [ASP.NET MVP]
  • Start date
C

Cor Ligthert

Miha,
What do you think components.Dispose does?
It loops through all components it has and it disposes them plus few minor
things.
Exactly and therefore there is in my opinion to need to call them
individually although that they have a dispose method. Now you are writting
what I try to tell all the time in this thread.

:)

Cor
 
C

Chris Lyon [MSFT]

That's a good point Cor.

Let me rephrase then... If an object implements IDisposable, then you
should ensure Dispose gets called, whether that means calling Dispose
explicitly on that instance, or calling Dispose on a parent class which, in
turn, will dispose its children.

Hope that clears things up.
-Chris


--------------------

|
| Miha,
|
| >
| > What do you think components.Dispose does?
| > It loops through all components it has and it disposes them plus few
minor
| > things.
| >
| Exactly and therefore there is in my opinion to need to call them
| individually although that they have a dispose method. Now you are
writting
| what I try to tell all the time in this thread.
|
| :)
|
| Cor
|
|
|
 
C

Chris Lyon [MSFT]

Hi Miha


| > -Dispose is primarily used to released unmanaged resources, although
there
| > is nothing wrong with releasing managed resources inside Dispose as well
| > (Dataset is a good example of this).
|
| What exactly do you mean by releasing managed resources?
| DataSet actually doesn't implement Dispose it just inherits it.


Calling DataSet.Dispose will realease any resources used by
MarshalByValueComponent. Since the entire inheritence tree implements
IDisposable, it usually means there are resources (managed or unmanaged) to
release.

These are rules of thumb. Of course there may be classes than implement
Dispose when they don't really need resources released, but personally, I
would call Dispose unless I had a good reason not to.

Hope that helps
-Chris
 
C

Chris Lyon [MSFT]

Yes, I agree.

-Chris

--------------------
| | > Thanks Chris, this clarifies a lot. Would you agree with this -
| >
| > "There is a GC.SuppressFinalize on a dataset constructor because,
finalize
| > in a dataset doesn't really do anything."
|
| Sure.
|
| --
| Miha Markic [MVP C#] - RightHand .NET consulting & development
| www.rthand.com
| SLODUG - Slovene Developer Users Group www.codezone-si.info
|
|
|
 
M

Miha Markic [MVP C#]

"Chris Lyon [MSFT]" said:
Hi Miha


| > -Dispose is primarily used to released unmanaged resources, although
there
| > is nothing wrong with releasing managed resources inside Dispose as
well
| > (Dataset is a good example of this).
|
| What exactly do you mean by releasing managed resources?
| DataSet actually doesn't implement Dispose it just inherits it.


Calling DataSet.Dispose will realease any resources used by
MarshalByValueComponent. Since the entire inheritence tree implements
IDisposable, it usually means there are resources (managed or unmanaged)
to
release.

Just to make it clear. You really can't release managed resources. OTOH you
can release unmanaged ones.
At best, you can null references to managed instances...
For example, calling Form.Dispose will call Dispose of each contained
component and in turn each component will delegate the call down the tree -
ath the end all unmaanged resources should be free.
These are rules of thumb. Of course there may be classes than implement
Dispose when they don't really need resources released, but personally, I
would call Dispose unless I had a good reason not to.

Sure, no doubt about that.
 

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