473,378 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Idisposable

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
10 1555
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
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
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
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
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
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
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
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
=?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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Samuel R. Neff | last post by:
I'd like some opinions on whether or not to use IDisposable for classes that require clean-up but when the clean-up is not related to unmanaged resources or other disposable objects. The most...
5
by: Robert Heuvel | last post by:
Hi, this is what I did: public struct SWaitCursor:IDisposable { public SWaitCursor (int i) { Cursor.Current = Cursors.WaitCursor; } void System.IDisposable.Dispose() { Cursor.Current =...
3
by: Dave | last post by:
I trying to determine the best pattern for designing my business and data layers... Can the instance of the business object eventually cause memory leaks in Example 1? If your business class...
4
by: Helge Jensen | last post by:
In C# 2.0 System.IO.Stream is declared as: public class Stream: ..., IDisposable { ... public void Dispose(); public void Dispose(bool); IDisposable.Dispose(); } Which must be a...
4
by: phl | last post by:
hi, My question is: 1. To avoid possible memory leaks, when you use this pattern, after you have dealth with the unmanaged resources and before you take your object off the finalize queue,...
6
by: Water Cooler v2 | last post by:
I heard from someone that we must not implement IDisposable for all classes. Can someone please tell me: 1. the reason why we must not implement IDisposable for all the classes we write. 2....
12
by: Cordell Lawrence \(News Group\) | last post by:
There an ongoing discussion between a colleague and myself about the usefulness of the IDisposable pattern beyond the reclamation of unmanaged resources. The discussion is somewhat lengthy so I...
12
by: Mark Rae | last post by:
Hi, The following code works: HttpWebRequest objRequest = null; try { HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com"); using (HttpWebResponse...
11
by: Mark Rae | last post by:
Hi, Following on from the recent thread about why HttpWebRequest doesn't implement the IDisposable interface, I got to wondering whether people make their custom classes inherit IDisposable or...
3
by: Mark | last post by:
If your class implements IDisposable, I was told that this increases the speed with which your class is garbage collected. Is this true? And if so, how much "time" does it save? Assume that we...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.