Dispose Again!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cor Ligthert

    Re: Dispose Again!

    Jay,

    Thanks, I will try it tomorrow here, I let you know my experience with it.

    Cor


    Comment

    • Jay B. Harlow [MVP - Outlook]

      Re: Dispose Again!

      Michael,
      Using the following in a VS.NET 2003 Windows Forms application I get:

      Assemblies: 5
      Types: 3384
      Disposable: 226
      Dispose: 132

      There are significantly more then 5 assemblies in the entire .NET
      Framework...


      Const bindingAttr As BindingFlags = BindingFlags.De claredOnly _
      Or BindingFlags.In stance Or BindingFlags.Ig noreCase _
      Or BindingFlags.Pu blic Or BindingFlags.No nPublic
      Dim disposable As Type = GetType(IDispos able)
      Dim countAssemblies As Integer
      Dim countTypes As Integer
      Dim countDisposable As Integer
      Dim countDispose As Integer
      For Each a As [Assembly] In AppDomain.Curre ntDomain.GetAss emblies()
      countAssemblies += 1
      For Each t As Type In a.GetTypes()
      countTypes += 1
      If disposable.IsAs signableFrom(t) Then
      Debug.WriteLine (t.FullName, "IDisposabl e")
      countDisposable += 1
      End If
      Try
      If t.GetMethod("Di spose", bindingAttr) Is Nothing Then
      ' No Dispose method.
      Else
      Debug.WriteLine (t.FullName, "Dispose")
      countDispose += 1
      End If
      Catch ex As AmbiguousMatchE xception
      Debug.WriteLine (t.FullName, "Dispose(s) ")
      countDispose += 1
      End Try
      Next
      Next
      Debug.WriteLine (countAssemblie s, "Assemblies ")
      Debug.WriteLine (countTypes, "Types")
      Debug.WriteLine (countDisposabl e, "Disposable ")
      Debug.WriteLine (countDispose, "Dispose")

      NOTE: The "t.GetMetho d" is an attempt to see if there is any Dispose method
      declared on the type itself, as oppose to simply inheriting the method from
      a base class...

      Hope this helps
      Jay

      "Michael C#" <xyz@yomomma.co m> wrote in message
      news:OuwLVJyLFH A.3832@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Ahh, one down, 85 times X variations to go :) It seems like there are a
      > lot more than 85 classes, however. But then again, I might be counting
      > classes that are automatically excluded by virtue of not implementing
      > Dispose() anyway.
      >
      > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
      > news:OH1pXJxLFH A.1156@TK2MSFTN GP09.phx.gbl...[color=green]
      >> Michael,[color=darkred]
      >>> See, now we're making progress. Two down.[/color]
      >> I would consider it one type, that is System.Windows. Forms.Form.
      >>
      >> Consider a variation of the sample:
      >>
      >> Dim dialog As Form
      >>
      >> dialog = New OptionsDialog
      >> dialog.ShowDial og()
      >> dialog.Dispose( )
      >>
      >> dialog = New OptionsDialog
      >> dialog.Show()
      >>
      >> Its the exact same form, however based on how it is shown
      >> (Form.ShowDialo g or Form.Show) changes if Dispose is needed or not...
      >>[color=darkred]
      >>> Now how many classes does that leave? :)[/color]
      >> The following page suggests there are 85 classes. I'm not sure if that
      >> only includes types directly implementing IDisposable or if it includes
      >> types that inherit IDisposable from a base class also.
      >>
      >> http://www.vbinfozine.com/a_disposable.shtml
      >>
      >>
      >> I think the rule that is tripping people up (including the way I have
      >> stated things) is when IDisposable is in a base class (such as
      >> Component).
      >>
      >> Hope this helps
      >> Jay
      >>
      >>
      >> "Michael C#" <xyz@yomomma.co m> wrote in message
      >> news:%23PIzINwL FHA.3760@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
      >>> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in
      >>> message news:%23GywAJwL FHA.3296@TK2MSF TNGP15.phx.gbl. ..
      >>>> Consider objects that inherit from System.Windows. Forms.Form:
      >>>>
      >>>> Dim dialog As New OptionsDialog ' inherits Form
      >>>> dialog.ShowDial og()
      >>>> dialog.Dispose( )
      >>>>
      >>>> Dim child As New MidChildForm ' inherits Form
      >>>> child.Show()
      >>>
      >>> See, now we're making progress. Two down. Now how many classes does
      >>> that leave? :)
      >>>[/color]
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Jay B. Harlow [MVP - Outlook]

        Re: Dispose Again!

        Michael,
        This class follows the Dispose/Finalize pattern.

        Both Dispose() & Finalize() call Dispose(Boolean ).

        Hope this helps
        Jay

        "Michael C#" <xyz@yomomma.co m> wrote in message
        news:ej9S8ayLFH A.1308@TK2MSFTN GP15.phx.gbl...[color=blue]
        >
        > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
        > news:eCc7WRyLFH A.1308@TK2MSFTN GP15.phx.gbl...[color=green]
        >> Cor,[color=darkred]
        >>> frm.showdialog
        >>> frm.close ' the same routine is called when the mainform is closing.[/color]
        >> Yes same routine but for different reason, look at what the disposing
        >> parameter is.
        >>
        >>
        >> http://msdn.microsoft.com/library/de...poseTopic1.asp[/color]
        >
        > Uh-oh. You mean to tell me that for this class, Finalize invoketh
        > Dispose?
        >[/color]


        Comment

        • Scott M.

          Re: Dispose Again!

          > Your saying that Dispose is present because of the IDE and not the final[color=blue]
          > running application and that in that final running application, Dispose
          > has
          > no use.[/color]
          [color=blue][color=green][color=darkred]
          >>>I'm saying that's true in some cases.[/color][/color][/color]

          Well, actually you didn't say that the first time, you said:
          [color=blue][color=green]
          >> Web controls are the perfect example of that. At design time, they need
          >> to be disposed otherwise you'll squander windows resources. But at
          >> runtime, there's nothing to dispose. Also, if you think about it,
          >> there's no reasonable time for user code to dispose a web control at
          >> runtime (Page.Unload maybe?).[/color][/color]

          What I got from this was you saying "you don't need to dispose web form
          controls at run-time". And this is not true. As you say an OleDb
          connection object at run-time will be holding on to unmanaged resources that
          do not have anything to do with GDI and so this connection object should be
          disposed at run-time.
          [color=blue]
          > That is what I take issue with, that is what is completely false.[/color]
          [color=blue][color=green][color=darkred]
          >>>Well, gee, it's hard to argue with that impeccable logic. And you've
          >>>backed up your argument so well here with, well, pretty much nothing.[/color][/color][/color]

          And, gee, your sarcasm is something we can do without as well. Do you
          disagree that OleDb connections hold unmanaged resources? What part of
          saying that an OleDb connection needs to be disposed at run-time do you
          disagree with?



          Comment

          • Scott M.

            Re: Dispose Again!

            Hey Michael, take a breath and relax for a moment.

            I'm not trying to provoke you or cause an argument and I'd appreciate it if
            you laid off the sarcasm as I haven't thrown any at you.

            What I said (and you have blown completely out of proportion) was in
            response to a question that was asked for a simple and clear definition of
            what dispose is. What you've said is correct. I haven't and am not
            disputing it, so it's not necessary for you to continue to hammer me with
            the same text over and over.

            Believe it or not, there may be folks out there who may create classes from
            scratch (not explicitly inheriting from anything) and may not know anything
            about the Finalize() method (I think this thread proves that). These are 2
            pretty reasonable assumptions.

            In this circumstance, it would be the class designer's job to create a
            dispose and the class user's job to know to call it. My comments weren't
            really referring to existing classes.

            That's all I was saying. I never said "a class can't be created where its
            dispose method is automatically called by a finalizer". And since not all
            finalizers do call dispose, in fact, since not all classes even have a
            finalizer, I think my statement about dispose is pretty accurate.

            Sorry if this keeps you up at night.



            "Michael C#" <xyz@yomomma.co m> wrote in message
            news:OsFNeCvLFH A.580@TK2MSFTNG P15.phx.gbl...[color=blue]
            >
            > "Scott M." <s-mar@nospam.nosp am> wrote in message
            > news:OvM5yfpLFH A.4084@TK2MSFTN GP10.phx.gbl...[color=green][color=darkred]
            >>> "It is up to the class user to call this method [Dispose]."
            >>>
            >>> My original point, as desmonstrated by the Microsoft(tm)-sponsored
            >>> statement and code previously posted, is that the Finalize method can
            >>> call Dispose. The Finalize method is called via the GC. The GC normally
            >>> is not invoked by the "class user". It *can* happen; therefore the
            >>> statement is False.[/color]
            >>
            >> Uh, well, if in your book can=false, then ok.[/color]
            >
            > In my book the statement "It is up to the class user to call this method"
            > = false, as it is a documented fact that Dispose can be invoked by means
            > other than the "class user". Too easy Breezy.
            >[color=green]
            >> In my book, if I build a custom class that inherits from object and I
            >> create a Dispose method for it, the GC isn't going to do squat as far as
            >> calling my Dispose method. So, would I be wrong to reverse your logic
            >> and say that because it *might not* get called, my statement is true?
            >> Sure![/color]
            >
            > If you invoke Dispose in the Finalize method, as Microsoft has done in the
            > previously supplied sample code, then there is the possibility that it can
            > be invoked by GC. If you don't, then for that *one particular class*, it
            > cannot happen. However, based on the wild assumption that you're not the
            > only person in the Universe developing classes for the Framework (or just
            > maybe you are?) and that not everyone does things precisely the way you do
            > (some might even use Microsoft's own sample code as a starting point...
            > then again, this could be another wild and crazy out-of-bounds
            > assumption), it seems reasonable to conclude that there is at least one
            > class out there in the world in which the Finalize method invokes Dispose.
            > That one, single, lonely class which was not developed the "Scott M Way"
            > makes your gross generalization "false".
            >[/color]


            Comment

            • Scott M.

              Re: Dispose Again!

              Cor, have you lost your mind?!

              I am quoting YOU. YOU SAID: "There is no need to dispose any object of
              system.data."

              And then you have gone on to say that you didn't say it and now you are
              saying I am all the time writing something else. What are you talking
              about?!

              Go back and read your own posts, would you?


              "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
              news:uck1FbrLFH A.1884@TK2MSFTN GP15.phx.gbl...[color=blue]
              >
              > "Scott M." <s-mar@nospam.nosp am> schreef in bericht
              >[color=green]
              >> "There is no need to dispose any object of system.data."
              >>[/color]
              > Scott why are you writing that, you are all the time writing something
              > else dit you change your mind?
              >
              > To show you what misquoting is.
              >
              > Cor
              >[/color]


              Comment

              • Scott M.

                Re: Dispose Again!

                Well Michael, no offense to you, but I can do without your sarcasm and
                seemingly personal attacks on me.

                Your question makes perfect sense, and it is reasonable to think that a
                simple, clear concise answer should be given. But, you know what Michael?
                The answer isn't simple. To me, it seems that you want to blame me (or
                someone) because the simple, clear, concise answer you seek doesn't exist in
                that form.

                I am not aware of any complete text that lists the do's and don'ts of what
                to dispose or not. Instead, I am aware that circumstance by circumstance,
                one can determine if a particular class should or shouldn't be disposed.
                This is the best you are going to get, but you just won't accept that. And
                when this answer is given, you just seem to scream a little louder at the
                messenger about the message.

                You know what? Some objects in the real world are dangerous if swallowed.
                Can you please provide me with the complete list of those that are and those
                that aren't?



                "Michael C#" <xyz@yomomma.co m> wrote in message
                news:uupttQvLFH A.132@TK2MSFTNG P10.phx.gbl...[color=blue]
                > "Scott M." <s-mar@nospam.nosp am> wrote in message
                > news:er3HrgpLFH A.2384@tk2msftn gp13.phx.gbl...[color=green]
                >> You have heard if from the horses mouth, over and over in this thread:
                >>
                >> When a class uses unmanaged resources and exposes a Dispose method, call
                >> the Dispose method.
                >>
                >> This is what virtually all documentation on Dispose says. The rest of
                >> this thread is academic.
                >>[/color]
                >
                > Scott, no offense, but your every time I read your responses I am - for
                > some reason or other - reminded of the "Microsoft helicopter joke." While
                > your responses are - I'm sure - technically accurate, I'm not finding them
                > overly useful in addressing my only simple question. So I shall rephrase
                > more precisely: By *name*, *exactly* which classes, of the classes built
                > into the .NET Framework (*no user-created classes*), absolutely *require*
                > the use of Dispose() - and *exactly* which ones don't?
                >
                > I don't need consultant-like broad generalizations and sound bites
                > rehashed from the Marketing Department. I need to know exactly which
                > classes need to be disposed and which do not. That's all. End of story.
                >
                > If all you have is another quote from the Book of Architects like this one
                > (Chapter 12, Verse 13): "Useth Dispose only on classes uponeth which it
                > is required of thee, but neither on classes on which it is not exposed;
                > nor on classes that inherit it, excepting that it hath been overridden as
                > a plague of locusts upon the keyboard; or upon classes wherein thy
                > development has forsaken thy managed resources and delveth into thine pool
                > of unmanaged resources. Then shalt thou call they Dispose method. 'Thy
                > Finalize shalt not use thy Dispose in vain,' sayeth the Scott, 'only thine
                > class user shall ever calleth thy Dispose as this is the way of things.'
                > And out of the darkness the people cheered and feasted upon the potato
                > chips and Mountain Dew and they coded and were once again happy...", then
                > you can, for all intents and purposes, save it for surprise ending to a
                > book.
                >[/color]


                Comment

                • Michael C#

                  Re: Dispose Again!

                  I think this is where a large part of the disconnect between the two of us
                  in this conversation is. I'm trying to get answers about the use of Dispose
                  on existing classes built into the .NET Framework, and you're talking about
                  user-created classes. I keep trying to explain that this I'm not concerned
                  with user-created classes, but rather with the existing .NET classes, but
                  somehow I keep getting responses that are at best peripherally related to
                  the existing .NET classes.

                  Lay off the sarcasm? Like this, eh? "> Sorry if this keeps you up at
                  night."

                  God knows I'll definitely sleep better now.

                  "Scott M." <s-mar@nospam.nosp am> wrote in message
                  news:%23osSc7yL FHA.732@TK2MSFT NGP12.phx.gbl.. .[color=blue]
                  > Hey Michael, take a breath and relax for a moment.
                  >
                  > I'm not trying to provoke you or cause an argument and I'd appreciate it
                  > if you laid off the sarcasm as I haven't thrown any at you.
                  >
                  > What I said (and you have blown completely out of proportion) was in
                  > response to a question that was asked for a simple and clear definition of
                  > what dispose is. What you've said is correct. I haven't and am not
                  > disputing it, so it's not necessary for you to continue to hammer me with
                  > the same text over and over.
                  >
                  > Believe it or not, there may be folks out there who may create classes
                  > from scratch (not explicitly inheriting from anything) and may not know
                  > anything about the Finalize() method (I think this thread proves that).
                  > These are 2 pretty reasonable assumptions.
                  >
                  > In this circumstance, it would be the class designer's job to create a
                  > dispose and the class user's job to know to call it. My comments weren't
                  > really referring to existing classes.
                  >
                  > That's all I was saying. I never said "a class can't be created where its
                  > dispose method is automatically called by a finalizer". And since not all
                  > finalizers do call dispose, in fact, since not all classes even have a
                  > finalizer, I think my statement about dispose is pretty accurate.
                  >
                  > Sorry if this keeps you up at night.
                  >
                  >
                  >
                  > "Michael C#" <xyz@yomomma.co m> wrote in message
                  > news:OsFNeCvLFH A.580@TK2MSFTNG P15.phx.gbl...[color=green]
                  >>
                  >> "Scott M." <s-mar@nospam.nosp am> wrote in message
                  >> news:OvM5yfpLFH A.4084@TK2MSFTN GP10.phx.gbl...[color=darkred]
                  >>>> "It is up to the class user to call this method [Dispose]."
                  >>>>
                  >>>> My original point, as desmonstrated by the Microsoft(tm)-sponsored
                  >>>> statement and code previously posted, is that the Finalize method can
                  >>>> call Dispose. The Finalize method is called via the GC. The GC
                  >>>> normally is not invoked by the "class user". It *can* happen;
                  >>>> therefore the statement is False.
                  >>>
                  >>> Uh, well, if in your book can=false, then ok.[/color]
                  >>
                  >> In my book the statement "It is up to the class user to call this method"
                  >> = false, as it is a documented fact that Dispose can be invoked by means
                  >> other than the "class user". Too easy Breezy.
                  >>[color=darkred]
                  >>> In my book, if I build a custom class that inherits from object and I
                  >>> create a Dispose method for it, the GC isn't going to do squat as far as
                  >>> calling my Dispose method. So, would I be wrong to reverse your logic
                  >>> and say that because it *might not* get called, my statement is true?
                  >>> Sure![/color]
                  >>
                  >> If you invoke Dispose in the Finalize method, as Microsoft has done in
                  >> the previously supplied sample code, then there is the possibility that
                  >> it can be invoked by GC. If you don't, then for that *one particular
                  >> class*, it cannot happen. However, based on the wild assumption that
                  >> you're not the only person in the Universe developing classes for the
                  >> Framework (or just maybe you are?) and that not everyone does things
                  >> precisely the way you do (some might even use Microsoft's own sample code
                  >> as a starting point... then again, this could be another wild and crazy
                  >> out-of-bounds assumption), it seems reasonable to conclude that there is
                  >> at least one class out there in the world in which the Finalize method
                  >> invokes Dispose. That one, single, lonely class which was not developed
                  >> the "Scott M Way" makes your gross generalization "false".
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  • Michael C#

                    Re: Dispose Again!

                    OleDb Connections need to be disposed. 2 down, 83 to go!

                    "Scott M." <s-mar@nospam.nosp am> wrote in message
                    news:uLjYE1yLFH A.4028@tk2msftn gp13.phx.gbl...[color=blue][color=green]
                    >> Your saying that Dispose is present because of the IDE and not the final
                    >> running application and that in that final running application, Dispose
                    >> has
                    >> no use.[/color]
                    >[color=green][color=darkred]
                    >>>>I'm saying that's true in some cases.[/color][/color]
                    >
                    > Well, actually you didn't say that the first time, you said:
                    >[color=green][color=darkred]
                    >>> Web controls are the perfect example of that. At design time, they need
                    >>> to be disposed otherwise you'll squander windows resources. But at
                    >>> runtime, there's nothing to dispose. Also, if you think about it,
                    >>> there's no reasonable time for user code to dispose a web control at
                    >>> runtime (Page.Unload maybe?).[/color][/color]
                    >
                    > What I got from this was you saying "you don't need to dispose web form
                    > controls at run-time". And this is not true. As you say an OleDb
                    > connection object at run-time will be holding on to unmanaged resources
                    > that do not have anything to do with GDI and so this connection object
                    > should be disposed at run-time.
                    >[color=green]
                    >> That is what I take issue with, that is what is completely false.[/color]
                    >[color=green][color=darkred]
                    >>>>Well, gee, it's hard to argue with that impeccable logic. And you've
                    >>>>backed up your argument so well here with, well, pretty much nothing.[/color][/color]
                    >
                    > And, gee, your sarcasm is something we can do without as well. Do you
                    > disagree that OleDb connections hold unmanaged resources? What part of
                    > saying that an OleDb connection needs to be disposed at run-time do you
                    > disagree with?
                    >
                    >
                    >[/color]


                    Comment

                    • Michael C#

                      Re: Dispose Again!

                      "Scott M." <s-mar@nospam.nosp am> wrote in message
                      news:%23ER%232B zLFHA.2136@TK2M SFTNGP14.phx.gb l...[color=blue]
                      > Well Michael, no offense to you, but I can do without your sarcasm and
                      > seemingly personal attacks on me.[/color]

                      Nothing personal. But I could do without your generic answers directed at
                      me that relate to questions which I am not asking. As stated, I'm not
                      asking about user-created classes, yet I keep getting user-created class
                      hints, tips and answers. I'm not asking about broad generalities, but I
                      keep getting broad generalities.
                      [color=blue]
                      > Your question makes perfect sense, and it is reasonable to think that a
                      > simple, clear concise answer should be given. But, you know what Michael?
                      > The answer isn't simple. To me, it seems that you want to blame me (or
                      > someone) because the simple, clear, concise answer you seek doesn't exist
                      > in that form.
                      >
                      > I am not aware of any complete text that lists the do's and don'ts of what
                      > to dispose or not. Instead, I am aware that circumstance by circumstance,
                      > one can determine if a particular class should or shouldn't be disposed.
                      > This is the best you are going to get, but you just won't accept that.
                      > And when this answer is given, you just seem to scream a little louder at
                      > the messenger about the message.[/color]

                      The only problem I have with you, Scott, is that you keep answering the
                      wrong question. If you don't know the answer, I definitely won't hold it
                      against you, just say "I don't know the answer to the question you're
                      asking" and let someone else who might know take a shot at answering.
                      [color=blue]
                      > You know what? Some objects in the real world are dangerous if swallowed.
                      > Can you please provide me with the complete list of those that are and
                      > those that aren't?[/color]

                      So glad you asked!!! There are three "rules" in determining what to
                      swallow:

                      1) Never swallow anything
                      2) Swallow everything
                      3) Swallow only non-harmful things

                      Some people live by Rule #2, but I try to strive for Rule #3.

                      Hope that answered your question as well as you've answered mine!


                      Comment

                      • Scott M.

                        Re: Dispose Again!

                        Cor, please! READ MY POSTS before responding.

                        Did I say you used the word elaborate? No, I said you "seem to keep trying
                        to elaborate". Do you know what that means?


                        "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                        news:ew6IqPrLFH A.3336@TK2MSFTN GP10.phx.gbl...[color=blue]
                        > Scott,
                        >[color=green]
                        >> Sorry Cor, but I am quoting you. This is what you said. I responded to
                        >> it.
                        >>
                        >> You seem to keep trying to elaborate and each time, you seem to
                        >> contradict yourself. At this point, I really don't know what you are
                        >> saying.
                        >>
                        >> My thoughts on this are stated throughout the thread, but to sum up: I
                        >> agree that everything doesn't *need* to be disposed (labels), but data
                        >> objects most certainly do.
                        >>[/color]
                        > I never use the word elaborate where did I write that?
                        >
                        > Cor.
                        >[/color]


                        Comment

                        • Scott M.

                          Re: Dispose Again!

                          > Lay off the sarcasm? Like this, eh? "> Sorry if this keeps you up at[color=blue]
                          > night."
                          >
                          > God knows I'll definitely sleep better now.[/color]

                          That wasn't sarcasm. That was the only conclusion I could come up with why
                          you seem to be taking your frustrations out on me. This is what I call
                          sarcasm:

                          "However, based on the wild assumption that you're not the
                          only person in the Universe developing classes for the Framework (or just
                          maybe you are?) and that not everyone does things precisely the way you do
                          (some might even use Microsoft's own sample code as a starting point...
                          then again, this could be another wild and crazy out-of-bounds assumption),
                          it seems reasonable to conclude that there is at least one class out there
                          in the world in which the Finalize method invokes Dispose. That one,
                          single, lonely class which was not developed the "Scott M Way" makes your
                          gross generalization "false". "





                          Comment

                          • Scott M.

                            Re: Dispose Again!

                            > Nothing personal. But I could do without your generic answers directed at[color=blue]
                            > me that relate to questions which I am not asking. As stated, I'm not
                            > asking about user-created classes, yet I keep getting user-created class
                            > hints, tips and answers. I'm not asking about broad generalities, but I
                            > keep getting broad generalities.[/color]

                            You have every right to not respond to information you deem not related to
                            you. You do not have the right to be sarcastic and borderline mean to
                            people posting information in a public place with the best of intentions for
                            all to consume.
                            [color=blue]
                            > The only problem I have with you, Scott, is that you keep answering the
                            > wrong question. If you don't know the answer, I definitely won't hold it
                            > against you, just say "I don't know the answer to the question you're
                            > asking" and let someone else who might know take a shot at answering.[/color]

                            Again, I gave you the answer (below), you just don't want to accept it.

                            [I am not aware of any complete text that lists the do's and don'ts of what
                            to dispose or not. Instead, I am aware that circumstance by circumstance,
                            one can determine if a particular class should or shouldn't be disposed.]
                            [color=blue][color=green]
                            >> You know what? Some objects in the real world are dangerous if
                            >> swallowed. Can you please provide me with the complete list of those that
                            >> are and those that aren't?[/color]
                            >
                            > So glad you asked!!! There are three "rules" in determining what to
                            > swallow:
                            >
                            > 1) Never swallow anything
                            > 2) Swallow everything
                            > 3) Swallow only non-harmful things
                            >
                            > Some people live by Rule #2, but I try to strive for Rule #3.
                            >
                            > Hope that answered your question as well as you've answered mine![/color]

                            Ah but see, you didn't answer the question that "I was asking". See, I
                            didn't ask what you or other people eat, I asked for a complete list of what
                            is and isn't harmful to eat. So as soon as you get that list to me, I'll
                            get you the imaginary list you are looking for.




                            Comment

                            • Michael C#

                              Re: Dispose Again!

                              "Scott M." <s-mar@nospam.nosp am> wrote in message
                              news:uo0mErzLFH A.732@TK2MSFTNG P12.phx.gbl...[color=blue]
                              > Again, I gave you the answer (below), you just don't want to accept it.
                              >
                              > [I am not aware of any complete text that lists the do's and don'ts of
                              > what
                              > to dispose or not. Instead, I am aware that circumstance by circumstance,
                              > one can determine if a particular class should or shouldn't be disposed.][/color]

                              Of course I can readily accept the fact that you do not know this
                              information; however, you must accept the fact that someone else may know,
                              or at least be aware of good resources for finding, this specific
                              information.
                              [color=blue][color=green][color=darkred]
                              >>> You know what? Some objects in the real world are dangerous if
                              >>> swallowed. Can you please provide me with the complete list of those
                              >>> that are and those that aren't?[/color]
                              >>
                              >> So glad you asked!!! There are three "rules" in determining what to
                              >> swallow:
                              >>
                              >> 1) Never swallow anything
                              >> 2) Swallow everything
                              >> 3) Swallow only non-harmful things[/color]
                              >
                              > Ah but see, you didn't answer the question that "I was asking". See, I
                              > didn't ask what you or other people eat, I asked for a complete list of
                              > what is and isn't harmful to eat. So as soon as you get that list to me,
                              > I'll get you the imaginary list you are looking for.[/color]

                              Ah, now perhaps you understand my frustration with your "answers" to my
                              question. Perhaps not.

                              Like you, I didn't ask what you or other people Dispose, I asked for a
                              complete list of what should and should not be Disposed. Which should make
                              a much, much shorter list than items that can be swallowed. After all,
                              there are far more things that can be "swallowed" than there are built-in
                              classes in the .NET Framework that expose a Dispose method; however, as you
                              can see, your answers apply to this situation (and probably any other
                              situation you could possibly think up), without losing any of their
                              practical value.

                              Now, if you want to get into more practical detail, we could look at all
                              objects that expose a "Swallow" method. We can further refine the "list" to
                              "you will learn what not to swallow by experience" (you will learn when to
                              use Dispose by experience), "you can teach yourself advanced Chemistry and
                              Biology courses and perform chemical analysis on everything that has a
                              Swallow method" (after all you can learn IL and use ILDASM and Object
                              Browser to determine which objects to Dispose), you can follow the
                              Manufacturer's Recommendations for Swallowing - assuming there are any, and
                              make note of the exceptions. I can also tell you that it is correct to
                              swallow chocolate milk and chicken casserole based on their Swallow
                              interfaces. That's 2 down, how many to go?


                              Comment

                              • Michael C#

                                Re: Dispose Again!

                                Now *that* is an excellent tool to discover a baseline. Thank you.

                                IMHO, MS just needs to dedicate a person or two to documenting this and
                                letting people know when and how to use their product; rather than leaving
                                it to people to accidentally discover, or spend hours researching this when
                                they could be doing far more productive things. It would seem the next step
                                would be to determine if the Dispose and Disposable types use unmanaged
                                resources. Do you think there is a programmatic way to determine this?

                                "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                                news:eZDpRqyLFH A.4092@tk2msftn gp13.phx.gbl...[color=blue]
                                > Michael,
                                > Using the following in a VS.NET 2003 Windows Forms application I get:
                                >
                                > Assemblies: 5
                                > Types: 3384
                                > Disposable: 226
                                > Dispose: 132
                                >
                                > There are significantly more then 5 assemblies in the entire .NET
                                > Framework...
                                >
                                >
                                > Const bindingAttr As BindingFlags = BindingFlags.De claredOnly _
                                > Or BindingFlags.In stance Or BindingFlags.Ig noreCase _
                                > Or BindingFlags.Pu blic Or BindingFlags.No nPublic
                                > Dim disposable As Type = GetType(IDispos able)
                                > Dim countAssemblies As Integer
                                > Dim countTypes As Integer
                                > Dim countDisposable As Integer
                                > Dim countDispose As Integer
                                > For Each a As [Assembly] In AppDomain.Curre ntDomain.GetAss emblies()
                                > countAssemblies += 1
                                > For Each t As Type In a.GetTypes()
                                > countTypes += 1
                                > If disposable.IsAs signableFrom(t) Then
                                > Debug.WriteLine (t.FullName, "IDisposabl e")
                                > countDisposable += 1
                                > End If
                                > Try
                                > If t.GetMethod("Di spose", bindingAttr) Is Nothing Then
                                > ' No Dispose method.
                                > Else
                                > Debug.WriteLine (t.FullName, "Dispose")
                                > countDispose += 1
                                > End If
                                > Catch ex As AmbiguousMatchE xception
                                > Debug.WriteLine (t.FullName, "Dispose(s) ")
                                > countDispose += 1
                                > End Try
                                > Next
                                > Next
                                > Debug.WriteLine (countAssemblie s, "Assemblies ")
                                > Debug.WriteLine (countTypes, "Types")
                                > Debug.WriteLine (countDisposabl e, "Disposable ")
                                > Debug.WriteLine (countDispose, "Dispose")
                                >
                                > NOTE: The "t.GetMetho d" is an attempt to see if there is any Dispose
                                > method declared on the type itself, as oppose to simply inheriting the
                                > method from a base class...
                                >
                                > Hope this helps
                                > Jay
                                >
                                > "Michael C#" <xyz@yomomma.co m> wrote in message
                                > news:OuwLVJyLFH A.3832@TK2MSFTN GP12.phx.gbl...[color=green]
                                >> Ahh, one down, 85 times X variations to go :) It seems like there are a
                                >> lot more than 85 classes, however. But then again, I might be counting
                                >> classes that are automatically excluded by virtue of not implementing
                                >> Dispose() anyway.
                                >>
                                >> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                                >> news:OH1pXJxLFH A.1156@TK2MSFTN GP09.phx.gbl...[color=darkred]
                                >>> Michael,
                                >>>> See, now we're making progress. Two down.
                                >>> I would consider it one type, that is System.Windows. Forms.Form.
                                >>>
                                >>> Consider a variation of the sample:
                                >>>
                                >>> Dim dialog As Form
                                >>>
                                >>> dialog = New OptionsDialog
                                >>> dialog.ShowDial og()
                                >>> dialog.Dispose( )
                                >>>
                                >>> dialog = New OptionsDialog
                                >>> dialog.Show()
                                >>>
                                >>> Its the exact same form, however based on how it is shown
                                >>> (Form.ShowDialo g or Form.Show) changes if Dispose is needed or not...
                                >>>
                                >>>> Now how many classes does that leave? :)
                                >>> The following page suggests there are 85 classes. I'm not sure if that
                                >>> only includes types directly implementing IDisposable or if it includes
                                >>> types that inherit IDisposable from a base class also.
                                >>>
                                >>> http://www.vbinfozine.com/a_disposable.shtml
                                >>>
                                >>>
                                >>> I think the rule that is tripping people up (including the way I have
                                >>> stated things) is when IDisposable is in a base class (such as
                                >>> Component).
                                >>>
                                >>> Hope this helps
                                >>> Jay
                                >>>
                                >>>
                                >>> "Michael C#" <xyz@yomomma.co m> wrote in message
                                >>> news:%23PIzINwL FHA.3760@TK2MSF TNGP12.phx.gbl. ..
                                >>>> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in
                                >>>> message news:%23GywAJwL FHA.3296@TK2MSF TNGP15.phx.gbl. ..
                                >>>>> Consider objects that inherit from System.Windows. Forms.Form:
                                >>>>>
                                >>>>> Dim dialog As New OptionsDialog ' inherits Form
                                >>>>> dialog.ShowDial og()
                                >>>>> dialog.Dispose( )
                                >>>>>
                                >>>>> Dim child As New MidChildForm ' inherits Form
                                >>>>> child.Show()
                                >>>>
                                >>>> See, now we're making progress. Two down. Now how many classes does
                                >>>> that leave? :)
                                >>>>
                                >>>
                                >>>[/color]
                                >>
                                >>[/color]
                                >
                                >[/color]


                                Comment

                                Working...