By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Idisposable

P: n/a
VB.Net Documentation for implementing IDisposable has:

Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
' Free other state (managed objects).
End If
Tag.Dispose()
' Free your own state (unmanaged objects).
' Set large fields to null.
End Sub

I am having trouble understanding the comments:
What does "state (managed objects)" mean
What does "state (unmanaged objects)" mean
I understand managed objects and unmanaged objects like com objects, certain
GDI objects are unmanaged and should be disposed here. But what does the
"state" mean?

--
Dennis in Houston
Nov 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
It just means that the object would free itself from whatever resources it
was holding, thus it would no longer be statefull. Don't let the wording
hang you up.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
VB.Net Documentation for implementing IDisposable has:

Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
' Free other state (managed objects).
End If
Tag.Dispose()
' Free your own state (unmanaged objects).
' Set large fields to null.
End Sub

I am having trouble understanding the comments:
What does "state (managed objects)" mean
What does "state (unmanaged objects)" mean
I understand managed objects and unmanaged objects like com objects,
certain
GDI objects are unmanaged and should be disposed here. But what does the
"state" mean?

--
Dennis in Houston

Nov 21 '05 #2

P: n/a
Thanks. I guess the State just means that the instance of it exists and the
managed objects will free themselves (sometime) whereas I have to free all my
own state unmanaged objects like the GDI pens, etc.

"Scott M." wrote:
It just means that the object would free itself from whatever resources it
was holding, thus it would no longer be statefull. Don't let the wording
hang you up.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
VB.Net Documentation for implementing IDisposable has:

Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
' Free other state (managed objects).
End If
Tag.Dispose()
' Free your own state (unmanaged objects).
' Set large fields to null.
End Sub

I am having trouble understanding the comments:
What does "state (managed objects)" mean
What does "state (unmanaged objects)" mean
I understand managed objects and unmanaged objects like com objects,
certain
GDI objects are unmanaged and should be disposed here. But what does the
"state" mean?

--
Dennis in Houston


Nov 21 '05 #3

P: n/a
Scott, it would be very helpful if you could give me an example of :

a State Managed Object and a "your own State unmanaged object. For example,
is a GDI Pen "state managed object" or my own state managed object"

I really appreciate you helping me to understand this.

"Dennis" wrote:
VB.Net Documentation for implementing IDisposable has:

Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
' Free other state (managed objects).
End If
Tag.Dispose()
' Free your own state (unmanaged objects).
' Set large fields to null.
End Sub

I am having trouble understanding the comments:
What does "state (managed objects)" mean
What does "state (unmanaged objects)" mean
I understand managed objects and unmanaged objects like com objects, certain
GDI objects are unmanaged and should be disposed here. But what does the
"state" mean?

--
Dennis in Houston

Nov 21 '05 #4

P: n/a
Hi Dennis,

I really don't know what a GDI Pen object is (I have no experience with it.
Having said that, it's really pretty simple...managed objects are classes
that are instanced from and their code is run 100% by the Common Language
Runtime. Many of the classes in the .NET Framework are 100% managed
objects. Some however, are not. An OLEDBConnection is not 100% managed
because the underlying OLEDB Provider is COM based.

An unmanaged object is a class that is NOT instanced by the CLR. So, any
non .NET objects (COM for example) would qualify here. Examples of
unmanaged objects would be any ActiveX control or other COM objects like
automating Office classes.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
Scott, it would be very helpful if you could give me an example of :

a State Managed Object and a "your own State unmanaged object. For
example,
is a GDI Pen "state managed object" or my own state managed object"

I really appreciate you helping me to understand this.

"Dennis" wrote:
VB.Net Documentation for implementing IDisposable has:

Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
' Free other state (managed objects).
End If
Tag.Dispose()
' Free your own state (unmanaged objects).
' Set large fields to null.
End Sub

I am having trouble understanding the comments:
What does "state (managed objects)" mean
What does "state (unmanaged objects)" mean
I understand managed objects and unmanaged objects like com objects,
certain
GDI objects are unmanaged and should be disposed here. But what does the
"state" mean?

--
Dennis in Houston

Nov 21 '05 #5

P: n/a
Dennis,

"Dennis" <De****@discussions.microsoft.com> schrieb:
a State Managed Object and a "your own State unmanaged object. For
example,
is a GDI Pen "state managed object" or my own state managed object"


You should call a pen's 'Dispose' method explicitly when the class'
'Dispose' method is called.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6

P: n/a
Thanks...I understand a lot more now. I guess I can tell if a .net object is
100% managed if it doesn't have a dispose method and vice versa, if it has a
dispose method then it's not 100% managed.

"Scott M." wrote:
Hi Dennis,

I really don't know what a GDI Pen object is (I have no experience with it.
Having said that, it's really pretty simple...managed objects are classes
that are instanced from and their code is run 100% by the Common Language
Runtime. Many of the classes in the .NET Framework are 100% managed
objects. Some however, are not. An OLEDBConnection is not 100% managed
because the underlying OLEDB Provider is COM based.

An unmanaged object is a class that is NOT instanced by the CLR. So, any
non .NET objects (COM for example) would qualify here. Examples of
unmanaged objects would be any ActiveX control or other COM objects like
automating Office classes.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
Scott, it would be very helpful if you could give me an example of :

a State Managed Object and a "your own State unmanaged object. For
example,
is a GDI Pen "state managed object" or my own state managed object"

I really appreciate you helping me to understand this.

"Dennis" wrote:
VB.Net Documentation for implementing IDisposable has:

Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
' Free other state (managed objects).
End If
Tag.Dispose()
' Free your own state (unmanaged objects).
' Set large fields to null.
End Sub

I am having trouble understanding the comments:
What does "state (managed objects)" mean
What does "state (unmanaged objects)" mean
I understand managed objects and unmanaged objects like com objects,
certain
GDI objects are unmanaged and should be disposed here. But what does the
"state" mean?

--
Dennis in Houston


Nov 21 '05 #7

P: n/a
Dennis,

IDisposable defines a method to release allocated unmanaged resources.
Unfortunality is this very inconsequently used (even on MSDN) and is as well
spoken about unmanaged objects, what gives in my idea the big
misunderstandings about this.

In my opinion does dotNet itself not know unmanaged objects.

Just my thought,

Cor
Nov 21 '05 #8

P: n/a
I agree. You'd think that M'soft could write a system like .Net that knew
what an unmanaged object is. Better yet, why don't they finish .Net so
unmanaged objects aren't needed. I get tired of "disposing" of simple things
like Pens, Brushes, Data Base connections, etc. Every time I use one of the
..Net objects, I have to check to see if it has a Dispose method.

"Cor Ligthert" wrote:
Dennis,

IDisposable defines a method to release allocated unmanaged resources.
Unfortunality is this very inconsequently used (even on MSDN) and is as well
spoken about unmanaged objects, what gives in my idea the big
misunderstandings about this.

In my opinion does dotNet itself not know unmanaged objects.

Just my thought,

Cor

Nov 21 '05 #9

P: n/a
=?Utf-8?B?RGVubmlz?= <De****@discussions.microsoft.com> wrote in
news:89**********************************@microsof t.com:
I agree. You'd think that M'soft could write a system like .Net that
knew what an unmanaged object is. Better yet, why don't they finish
.Net so unmanaged objects aren't needed. I get tired of "disposing" of
simple things like Pens, Brushes, Data Base connections, etc. Every
time I use one of the Net objects, I have to check to see if it has a
Dispose method.


I agree that is a major PITA. For one - using should be able to be used
WHETHER or not it has a dispose...

But the underyling model of unmanaged vs managed is solid - and we will
always need the option for finalizatino and unmanaged objects. The problem
comes from a less than optimal implementation in the C# language (and even
worse in VB). Im not going to tout that Delphi is better - but how Borland
did Delphi.NET IMO is a lot more consistent and cleaner in many ways. In some
ways its less clean though because of compatibility with non .NET Delphi
though.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 21 '05 #10

P: n/a
Dennis,
Better yet, why don't they finish .Net so
unmanaged objects aren't needed. IDisposable will still be needed/usable!

Consider limited 100% managed resources that are handed out my some form of
manager/repository class. IDisposable can be used to inform the object that
you are done with it, allowing the object to inform the manager/repostitory
its free now. Both the manager/repostitory & the class itself are 100%
managed...
VB.NET 2005 (aka Whidbey, due out later in 2005) in fact simplifies
IDisposable by adding the Using statement.

http://msdn2.microsoft.com/library/htd05whh.aspx

Using thePen As New Pen(...)
gr.DrawLine(thePen, ...)
gr.DrawLine(thePen, ...)
gr.DrawLine(thePen, ...)
gr.DrawLine(thePen, ...)
End Using

Then you only need to worry about using the pen, and not worry about
IDisposable or a Try/Finally.

Hope this helps
Jay
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...I agree. You'd think that M'soft could write a system like .Net that knew
what an unmanaged object is. Better yet, why don't they finish .Net so
unmanaged objects aren't needed. I get tired of "disposing" of simple
things
like Pens, Brushes, Data Base connections, etc. Every time I use one of
the
.Net objects, I have to check to see if it has a Dispose method.

"Cor Ligthert" wrote:
Dennis,

IDisposable defines a method to release allocated unmanaged resources.
Unfortunality is this very inconsequently used (even on MSDN) and is as
well
spoken about unmanaged objects, what gives in my idea the big
misunderstandings about this.

In my opinion does dotNet itself not know unmanaged objects.

Just my thought,

Cor

Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.