Dispose Again!

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

    #76
    Re: Dispose Again!

    On 2005-03-20, Jay B. Harlow [MVP - Outlook] <Jay_Harlow_MVP @msn.com> wrote:[color=blue]
    > Michael and Dennis,[color=green]
    >> So again, we get back to someone's recommendations somewhere; presumably
    >> the class developer's recommendation.[/color]
    >
    > As JD has suggested Dispose can do one of three things:
    >
    > 1) nothing
    > 2) cleans up unmanaged resources
    > 3) cleans up managed resources[/color]


    True, but I think this hides what is really the cause of most of the
    confusion around Dispose, which is that Dispose can do different things
    at different times.

    Most commonly, there's an awful lot of objects that don't need to be
    disposed at runtime but have a visual representation of themselves in
    Visual Studio that *does* need to be disposed.

    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?).

    This may have been what Cor was getting at earlier. All the standard
    System.Data objects: Connections, DataAdapters, DataSets, DataReaders,
    none of them need to be disposed at runtime. It doesn't hurt anything
    to call Dispose on them, it just does nothing useful (you *do* have to
    close them, and Dispose will call Close for you if necessary, but that's
    something else). But they all have visual representations that need to
    be disposed at design time, so they need to implement IDisposable.
    [color=blue]
    > Now IMHO there are 3 schools of thought on calling Dispose:
    >
    > 1) Never call Dispose, instead let the Finalizer take care of unmanaged
    > resources. This is probably the worst & sloppiest attitude you can take on
    > calling Dispose. Profiling & various exceptions will indicate problems when
    > using this method.
    >
    > 2) Always call Dispose, the "better safe then sorry" pattern.
    >
    > 3) "Appropriat ely" call Dispose. Unfortunately this is the hardest one to
    > achieve, as you need to learn from experience, others, or profiling &
    > various exceptions... It is the one I strife for...[/color]

    #3 is what most of us probably do, and it's the best solution for a bad
    problem IMHO.

    But in the land of inheritance and interfaces, there's the possibility
    here of a time bomb. I may know I don't have to Dispose a
    SqlDataAdapter or DataSet, but what if my DAL hands me an IDataAdapter
    from some weird implementation that needs disposing and or a DataSet
    object that *might be* a class that inherits DataSet, and needs to
    de-allocate precious resources in Dispose? Experience and profiling
    doesn't help here, since the type of object I'm receiving might change
    long after development has finished.

    I choose to pretty much ignore those issues right now. But tossing
    IDisposable on a ton of objects that don't actually need runtime
    disposing was a pretty bad idea on the part of MS.


    Comment

    • David

      #77
      Re: Dispose Again!

      On 2005-03-21, Scott M. <s-mar@nospam.nosp am> wrote:[color=blue]
      > No Cor, that is not what I'm referring to. What I've read about the
      > DataReader, Connection and DataAdapter classes is that they DO use unmanaged
      > resources and SHOULD be disposed. I'm not talking about labels here. You
      > said there is no reason to call dispose on any of the data classes. I must
      > disagree. I believe that to be incorrect.[/color]

      This depends a bit on the type of data resources you're using. The
      SqlClient stuff never needs to be disposed. OleDb objects, on the other
      hand, can use a tiny bit of COM memory and so possibly they should be
      Disposed (in practice I'm not so sure it matters).

      Of course, there's an awful lot of other data libraries out there and it
      would be hard to generalize about them.

      Comment

      • Cor Ligthert

        #78
        Re: Dispose Again!

        Michael
        [color=blue]
        > Yeah Cor, I just visited that new link and I still don't see how it
        > relates?
        >[/color]

        This was an answer on Jay, where he told that some classes in this list did
        not derive from component.

        It gives as well an answer on the question that from every method which have
        a dispose the dispose should be used. All those methods and which derive
        from those have a dispose just because it is in the top base class.

        Cor


        Comment

        • Cor Ligthert

          #79
          Re: Dispose Again!

          Scott,[color=blue]
          >
          > "There is no need to dispose any object of system.data."
          >
          > And that is what I responded to because that is untrue.
          >[/color]
          No that did I not say, because I showed you the message about connection and
          any dispose method can be overridden. However, for the rest I would not know
          any object in system.data that in my opinion *should* be disposed.

          About the system.data object has dispose often been in the newsgroup Adonet.
          I know that Angel has advised to dispose every object. However when I asked
          him once why, he told more or less that it was his personal way of doing
          things.

          However will never tell here in a newsgroup not to dispose, I tell to use it
          when it has sense, however not the sentence "When there is a dipose method
          it should be used".

          And that is what this thread in this message as answer on Dennis started
          with.
          [color=blue]
          > 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!"[/color]

          Cor


          Comment

          • Cor Ligthert

            #80
            Re: Dispose Again!

            Jay,
            [color=blue]
            > I'm sincerely sorry about the off color joke. It was meant purely as a
            > joke, and nothing about your culture.
            >[/color]

            Ok accepted.
            [color=blue]
            > However my question about what you are talking about in this thread still
            > stands![/color]

            I have taken some time about the dispose, because it is something where
            about in my opinion is very poorly about written and gets a different
            setting when you read about it in time from old documents to newer
            documents.

            The old are in the style, "do dispose because it can not hurt" while the
            newer get more another trend however still in my opinion not well described.
            You can see that in my opinion in that "Improving .NET Application
            Performance and Scalability" link you once showed me. There is a lot very
            good written, however the dispose has again that "it can not hurt" trend for
            me and is very brief written
            [color=blue]
            >Your statement may be (partially) true for the System.Data namespace
            >itself, however it is not even close to true for (most of)
            >System.Data.Od bc, System.Data.Ole Db, System.Data.Sql Client, and
            >System.Data.Or acleClient! As they all contain classes that deal with
            >"external" (aka unmanaged) resource.
            >As they all contain classes that deal with "external" (aka unmanaged)
            >resource.[/color]

            The big point for me is, that an unmanaged resource are in all documents
            indirectly and flaw connected with managed code. Managed code is to manage
            resources. There is not written something real about unmanaged resources in
            that relation. For me is as long that I don't have a good document what is
            an *unmanaged resource* (not a blog or whatever especially not from a
            classic VB MVP) an unmanaged resource something that comes from an API,
            wherefore than Idisposable should be implemented.

            We arguing in this thread part of the text bellow from Dennis, where I told
            to him that what he wrote was not the right method. As reaction on that you
            tell in this thread part, that I don't know what I am talking about.
            [color=blue]
            >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!"[/color]

            Therefore tell to me than what is wrong or smoked or whatever when I tell
            that this is not the right but even oposite from that. I have told that when
            you build your own class and it has unmanaged resource you would have to
            implement Idisposable (not in those words because I gave the advice to use
            components as base class where that is implemented).
            [color=blue]
            > There are times when what you state makes no sense (such as your answers
            > in this thread). There are times when your answers make a lot of sense!
            >[/color]
            I have told you more that when you *think* that when my answers as above
            don't make sense to ask. However you have than in my expirience the attitude
            to write than directly as if other people don't understand it. I told you
            more times, that I read documentation, however when I don't trust it,
            investigate it as far as I can go. Often when I wrote text like this you
            give an answer starting with (shakes
            head).......... ............... ............... .......
            [color=blue]
            > I'm certain it is not just me, as I've noticed others have questioned a
            > number of your answers also![/color]

            I am glad when people ask than. Than I try to clarify it, and when they
            *proof* that I am wrong I have learned something again and thank them.

            A sample from such a discussion where it was the oposite.

            [color=blue][color=green]
            >> You have lost all your credits from me.[/color][/color]
            [color=blue]
            > Unfortunately I cannot say the same about you! As you do provide valuable
            > information in the newsgroups. Its just sometimes (such as this thread) it
            > is hard to make heads or tails out of what you are saying. When I or
            > others ask for clarification of what you were thinking, you sometimes get
            > overly defensive or a little less coherent (such as posting the list of
            > classes).
            >[/color]
            A problem can be that I don't like the inline answers because they go
            everytime further and further away from the starting subject. I try to keep
            me on the subjects as they are top down in a thread. For some is that hard
            to read. When you want that, will I change that style for you as well as I
            did it for Herfried.

            And maybe by coincidence however because that you wrote now "Just a
            thought", when you write "I hope this helps" or just denies my answers
            without any proof or reference in it, or whithout the text "in my opinion" I
            probably become in a kind of what you call "overly defensive or a little
            less coherent". There are only two persons who can bring me in this state in
            these newsgroups. (The other one is not from this newsgroup and is now
            mostly ignored by me)

            As last about the list of classes. I expect that when you have written that
            something is "false" and I show a list wherin that is in my opinon "true"
            you understand what I mean.

            I hope this clarifice something.

            Cor


            Comment

            • Cor Ligthert

              #81
              Re: Dispose Again!

              Scott,
              [color=blue]
              > No Cor, that is not what I'm referring to. What I've read about the
              > DataReader, Connection and DataAdapter classes is that they DO use
              > unmanaged resources and SHOULD be disposed. I'm not talking about labels
              > here. You said there is no reason to call dispose on any of the data
              > classes. I must disagree. I believe that to be incorrect.
              >[/color]

              I have never stated that the Connection not *should* be disposed for at
              least a year now. So I cannot believe that you wrote is true. In opposite of
              that, I am always the one who advices in these newsgroups to use that
              instead of the close for the connection.

              My problem in this with the dispose is, that there is always written about
              unmanaged resources. However until now I never found a good link on MSDN
              what they mean with an "unmanaged resource", except some blogs from by
              instance old VB classic MVP's, which are often in conflict inside the text.

              Cor


              Comment

              • Cor Ligthert

                #82
                Re: Dispose Again!

                Michael,
                [color=blue]
                >This was an answer on Jay, where he told that some classes in this list did
                >not derive from component.[/color]

                Small correction again. That was the way I understood Jay's message because
                that was in my idea the main part. I readed the unmanaged resources part as
                an addition. I start to understand that his meaning about the message was
                more about the unmanaged resources part.

                Cor


                Comment

                • Michael C#

                  #83
                  Re: Dispose Again!


                  "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                  news:urWXVOcLFH A.3420@tk2msftn gp13.phx.gbl...[color=blue]
                  > IMHO the "set of rules" remains constant, by "set of rules" I mean JD's
                  > three rules which are rather simple. IMHO my list of 3 are more
                  > mantalities for managing JD's three rules...
                  >
                  > What would change is the list classes that now either "require" or not
                  > "require" dispose changes. I would expect classes that went from not
                  > requiring Dispose to now requiring Dispose to directly or indirectly to
                  > show up under the "Profiling & various exceptions" clause of my 3 rules...
                  >[/color]

                  IMHO, the "set of rules" you refer to are not rules at all; they are
                  patterns of usage. A rule would tell you, quite simply, "use Dispose() on
                  object x in situation y" or "don't use Dispose() on object x in situation
                  z". The "rules" I alluded to are the specific recommendations on usage
                  using pattern #3.

                  And I see we didn't even address my question, which is quite simply - and to
                  use your terms - when the "profiling & various exceptions" clause is
                  updated, how much time will be spent researching this, updating your usage
                  patterns, and finally updating any code you've currently completed?

                  It sounds to me like, to use pattern #3, you have to:

                  1) Perform a lot of research to determine the Developer's Recommendations ,
                  2) Perform a lot of research to figure out the "various exceptions",
                  3) Potentially spend a whole lot of time researching and adjusting your code
                  when the Developer Recommendations change.

                  From what you and others have posted, this esoteric information on Dispose()
                  usage is gained through trial and error, from others, and of course
                  developer recommendations . It appears that there is no definitive "list" of
                  "classes that now either 'require' or not 'require' dispose", and until
                  someone puts a definitive list together, it doesn't make a lot of sense to
                  reference it as if it were a click away. (BTW - If it *is* available, then
                  this whole thread can be boiled down to a simple link to this definitive
                  "list"... and shame on whoever knows the whereabouts of this list for not
                  posting the link already).

                  At this point I don't see a significant ROI on all this time and energy
                  spent on trial-and-erroring my way to this sliver of mysterious knowledge,
                  researching Developer's Recommendations on using Dispose() for every class I
                  use, or posting a new message every single time I run across an object that
                  exposes a Dispose() method. After all, I tested the third option with the
                  SqlCommand object in this thread days ago, and still haven't received a
                  simple "YES" or "NO" concerning whether or not it should be Disposed of!
                  Instead I get responses concerning "Labels" and patterns of usage: ("use it
                  all the time", "use it none of the time", "use it correctly")!

                  Imagine if you had to stop development for days each and every time you ran
                  across a new class that exposed Dispose(), so that you could post a
                  newsgroup message and await a response - which might or might not be
                  forthcoming. Alas, it's much simpler to consistently Dispose() of my
                  SqlCommand, SqlConnection and other objects when I'm done with them. I
                  would love to see a demonstration of how all the proposed research into this
                  arcane trivia generates anything greater than a personal sense of
                  accomplishment. ..
                  [color=blue][color=green]
                  >> Of the things lacking in VB, the C#-like "using" keyword is wayyyy at the
                  >> top of my list.[/color]
                  >
                  > As I've stated before, VB.NET 2005 will get the same "using" statement
                  > that C# has to help manage IDisposable classes...[/color]

                  Good, it's about time.
                  [color=blue]
                  > Hope this helps[/color]

                  Maybe not in the way you think, but thank you nonetheless.


                  Comment

                  • Jay B. Harlow [MVP - Outlook]

                    #84
                    Re: Dispose Again!

                    Cor,[color=blue]
                    > No that did I not say, because I showed you the message about[/color]

                    Yes! you did say that. :-|

                    The very first paragraph of:



                    States "There is no need to dispose of any object of system.data", end of
                    paragraph.


                    The other two paragraphs are hard to follow, but reading it again it appears
                    you are saying "There is no need to dispose of *most* objects in
                    system.data. however Connection is one you do need to Dispose". Which is the
                    point I was trying to make & trying to ask you about...

                    Jay



                    "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                    news:OGoorOeLFH A.656@TK2MSFTNG P14.phx.gbl...[color=blue]
                    > Scott,[color=green]
                    >>
                    >> "There is no need to dispose any object of system.data."
                    >>
                    >> And that is what I responded to because that is untrue.
                    >>[/color]
                    > No that did I not say, because I showed you the message about connection
                    > and any dispose method can be overridden. However, for the rest I would
                    > not know any object in system.data that in my opinion *should* be
                    > disposed.
                    >
                    > About the system.data object has dispose often been in the newsgroup
                    > Adonet. I know that Angel has advised to dispose every object. However
                    > when I asked him once why, he told more or less that it was his personal
                    > way of doing things.
                    >
                    > However will never tell here in a newsgroup not to dispose, I tell to use
                    > it when it has sense, however not the sentence "When there is a dipose
                    > method it should be used".
                    >
                    > And that is what this thread in this message as answer on Dennis started
                    > with.
                    >[color=green]
                    >> 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!"[/color]
                    >
                    > Cor
                    >[/color]


                    Comment

                    • Jay B. Harlow [MVP - Outlook]

                      #85
                      Re: Dispose Again!

                      Michael,[color=blue][color=green]
                      >> IMHO the "set of rules" remains constant, by "set of rules" I mean JD's[/color]
                      > IMHO, the "set of rules" you refer to are not rules at all; they are[/color]

                      Yes its a matter of perspective, not really worth splitting hairs over. :-)

                      I also consider JD's three & my three both to be "patterns" on one level or
                      another.

                      The "real" Dispose/Finalize pattern is the link to the Guidelines that I
                      posted once or twice in this thread. "Real" in that you should implement it
                      in your classes that is.

                      [color=blue]
                      > From what you and others have posted, this esoteric information on
                      > Dispose() usage is gained through trial and error, from others, and of
                      > course[/color]
                      I am not disputing that the situation as is, is not good.

                      [color=blue]
                      > 1) Perform a lot of research to determine the Developer's Recommendations ,
                      > 2) Perform a lot of research to figure out the "various exceptions",
                      > 3) Potentially spend a whole lot of time researching and adjusting your
                      > code when the Developer Recommendations change.[/color]

                      It really depends on what you define to be a lot. Depending on which
                      framework object model I am working on, varies how much research and/or
                      learning I will do. For example System.String & System.Text.Str ingBuilder I
                      simply start using (I will review the documentation of specific methods from
                      time to time to ensure that object/method is a good fit). However the
                      System.Data namespace I took the time to *learn* (rather then simple
                      research) how the DataSet object model actually works. I would expect any
                      Application Architect to do the same (as oppose to simple developers, who
                      should be working under the guidance of an Application Architect).

                      Normally I don't seek out exceptions, rather I let the subtle ones find me.
                      This is not to say that I don't make a note of the exceptions listed on each
                      method in the MSDN framework reference & plan accordingly...
                      [color=blue]
                      > Imagine if you had to stop development for days each and every time you
                      > ran across a new class that exposed Dispose(), so that you could post a
                      > newsgroup message and await a response - which might or might not be
                      > forthcoming. Alas, it's much simpler to consistently Dispose() of my[/color]
                      I would not stop development to ask! I would go to .NET Framework Reference
                      on MSDN & find out myself.



                      For larger "object models" such as the System.Data namespace I would review
                      other documentation on how to actually use the types in the namespace, such
                      books, other MSDN, and other internet articles.

                      If the class reference was inconclusive, I would decide to use Dispose or
                      not based on what the class was doing or how much I was using the class. As
                      has been discussed in this thread it will not really hurt if you call
                      Dispose when not needed, and usually will not hurt if you don't call Dispose
                      when needed.

                      If my program was then exhibiting performance or other negative behavior I
                      would use CLR profiler to "give it a check up".

                      Tools such as CLR profiler will identify classes that probably need to have
                      Dispose called, by virtue of the classes that are hogging the finalization
                      thread. For example use the "Call Tree View" to "analyze the use of
                      finalizers, including the number of finalizers executed". If you are
                      executing finalizers, then you are probably not calling Dispose. The
                      following article has an example that discusses calling & not calling
                      SolidBrush.Disp ose.



                      Of course if you are executing finalizers & don't have a Dispose method,
                      then the class designer probably needs to review the .NET Guidelines on the
                      Dispose/Finalize pattern...

                      Hope this helps
                      Jay

                      "Michael C#" <xyz@yomomma.co m> wrote in message
                      news:u$J65OjLFH A.2136@TK2MSFTN GP14.phx.gbl...[color=blue]
                      >
                      > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                      > news:urWXVOcLFH A.3420@tk2msftn gp13.phx.gbl...[color=green]
                      >> IMHO the "set of rules" remains constant, by "set of rules" I mean JD's
                      >> three rules which are rather simple. IMHO my list of 3 are more
                      >> mantalities for managing JD's three rules...
                      >>
                      >> What would change is the list classes that now either "require" or not
                      >> "require" dispose changes. I would expect classes that went from not
                      >> requiring Dispose to now requiring Dispose to directly or indirectly to
                      >> show up under the "Profiling & various exceptions" clause of my 3
                      >> rules...
                      >>[/color]
                      >
                      > IMHO, the "set of rules" you refer to are not rules at all; they are
                      > patterns of usage. A rule would tell you, quite simply, "use Dispose() on
                      > object x in situation y" or "don't use Dispose() on object x in situation
                      > z". The "rules" I alluded to are the specific recommendations on usage
                      > using pattern #3.
                      >
                      > And I see we didn't even address my question, which is quite simply - and
                      > to use your terms - when the "profiling & various exceptions" clause is
                      > updated, how much time will be spent researching this, updating your usage
                      > patterns, and finally updating any code you've currently completed?
                      >
                      > It sounds to me like, to use pattern #3, you have to:
                      >
                      > 1) Perform a lot of research to determine the Developer's Recommendations ,
                      > 2) Perform a lot of research to figure out the "various exceptions",
                      > 3) Potentially spend a whole lot of time researching and adjusting your
                      > code when the Developer Recommendations change.
                      >
                      > From what you and others have posted, this esoteric information on
                      > Dispose() usage is gained through trial and error, from others, and of
                      > course developer recommendations . It appears that there is no definitive
                      > "list" of "classes that now either 'require' or not 'require' dispose",
                      > and until someone puts a definitive list together, it doesn't make a lot
                      > of sense to reference it as if it were a click away. (BTW - If it *is*
                      > available, then this whole thread can be boiled down to a simple link to
                      > this definitive "list"... and shame on whoever knows the whereabouts of
                      > this list for not posting the link already).
                      >
                      > At this point I don't see a significant ROI on all this time and energy
                      > spent on trial-and-erroring my way to this sliver of mysterious knowledge,
                      > researching Developer's Recommendations on using Dispose() for every class
                      > I use, or posting a new message every single time I run across an object
                      > that exposes a Dispose() method. After all, I tested the third option
                      > with the SqlCommand object in this thread days ago, and still haven't
                      > received a simple "YES" or "NO" concerning whether or not it should be
                      > Disposed of! Instead I get responses concerning "Labels" and patterns of
                      > usage: ("use it all the time", "use it none of the time", "use it
                      > correctly")!
                      >
                      > Imagine if you had to stop development for days each and every time you
                      > ran across a new class that exposed Dispose(), so that you could post a
                      > newsgroup message and await a response - which might or might not be
                      > forthcoming. Alas, it's much simpler to consistently Dispose() of my
                      > SqlCommand, SqlConnection and other objects when I'm done with them. I
                      > would love to see a demonstration of how all the proposed research into
                      > this arcane trivia generates anything greater than a personal sense of
                      > accomplishment. ..
                      >[color=green][color=darkred]
                      >>> Of the things lacking in VB, the C#-like "using" keyword is wayyyy at
                      >>> the top of my list.[/color]
                      >>
                      >> As I've stated before, VB.NET 2005 will get the same "using" statement
                      >> that C# has to help manage IDisposable classes...[/color]
                      >
                      > Good, it's about time.
                      >[color=green]
                      >> Hope this helps[/color]
                      >
                      > Maybe not in the way you think, but thank you nonetheless.
                      >[/color]


                      Comment

                      • Michael C#

                        #86
                        Re: Dispose Again!

                        "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                        news:eYChnPcLFH A.904@tk2msftng p13.phx.gbl...[color=blue]
                        > The GC will never directly call Dispose! The GC will only directly call
                        > Finalize! Finalize may or may not call Dispose. Normally Dispose &
                        > Finalize will call a common routine.[/color]

                        I think you mentioned "splitting hairs", Jay? Allow me to modify my
                        statement to the following: The Dispose() method may be called from the
                        Finalize() routine, which can be called by the GC; which would mean that
                        it's not necessarily "up to the class user" to "call this method", which was
                        the actual point.



                        Hope that helps.

                        Thanks


                        Comment

                        • Michael C#

                          #87
                          Re: Dispose Again!

                          None of your links provide a definitive list of when to call Dispose() on
                          classes built into the .NET Framework Library. Not even the one that
                          describes how to implement Dispose in your own classes.

                          Based on what you've said, the only reason I can see for dilly-dallying
                          around Dispose() and not using it every single doggone time is for bragging
                          rights and self-stroking of one's ego (i.e., "I have this esoteric
                          knowledge, so I am better than a mere 'programmer'".) The bottom line is
                          that you have given no substantial reason to waste time researching and
                          categorizing when to call, and when not to call, Dispose() on classes that
                          expose it.

                          As for learning the inner workings of classes in the .NET Framework, I
                          always thought the entire point of High-Level OO Programming was to provide
                          programmers with "clock-work" functionality that they could count on to work
                          consistently without having to know how many "gears were in the box", or the
                          specific "gear measurements", etc. After all, if everything you've created
                          relies on the turning of those gears, what do you do with your work when
                          they switch you over to a digital clock? Case in point, why in the world do
                          I, while programming VB.NET, need to know that the Framework sets the AH,
                          BX, CX, DX, SI and DS registers before an INT 21H call in order to open a
                          file for me?

                          I was under the impression that the programmer should be shielded from the
                          inner tinkerings of the class, and that all you really need to -- or
                          should -- rely on is the fact that "if I passeth in 'X' it shall performeth
                          'Y' and returneth 'Z'"; and that you shouldn't bet the farm on the internal
                          workings of a class always achieving their results in the same manner as
                          they appear to do today. But that's just the "programmer " in me talking,
                          not "Le Architect".


                          Comment

                          • Scott M.

                            #88
                            Re: Dispose Again!

                            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.



                            "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                            news:OGoorOeLFH A.656@TK2MSFTNG P14.phx.gbl...[color=blue]
                            > Scott,[color=green]
                            >>
                            >> "There is no need to dispose any object of system.data."
                            >>
                            >> And that is what I responded to because that is untrue.
                            >>[/color]
                            > No that did I not say, because I showed you the message about connection
                            > and any dispose method can be overridden. However, for the rest I would
                            > not know any object in system.data that in my opinion *should* be
                            > disposed.
                            >
                            > About the system.data object has dispose often been in the newsgroup
                            > Adonet. I know that Angel has advised to dispose every object. However
                            > when I asked him once why, he told more or less that it was his personal
                            > way of doing things.
                            >
                            > However will never tell here in a newsgroup not to dispose, I tell to use
                            > it when it has sense, however not the sentence "When there is a dipose
                            > method it should be used".
                            >
                            > And that is what this thread in this message as answer on Dennis started
                            > with.
                            >[color=green]
                            >> 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!"[/color]
                            >
                            > Cor
                            >[/color]


                            Comment

                            • Scott M.

                              #89
                              Re: Dispose Again!

                              > Most commonly, there's an awful lot of objects that don't need to be[color=blue]
                              > disposed at runtime but have a visual representation of themselves in
                              > Visual Studio that *does* need to be disposed.
                              >
                              > 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]

                              Whoa Dave! Please explain yourself here (and in the paragraphs that
                              follow). You can't dispose anything at design-time, since these objects
                              aren't instantiated until run-time. Please don't make this topic even more
                              confused than it has become. Let's keep design-time out of this completely
                              as it is irrelevant - objects get instanced at run-time only. Run-time is
                              what we are talking about. The CLR isn't managing anything at design-time.
                              [color=blue]
                              > This may have been what Cor was getting at earlier. All the standard
                              > System.Data objects: Connections, DataAdapters, DataSets, DataReaders,
                              > none of them need to be disposed at runtime.[/color]

                              Nope, no, sorry, wrong, uh uh, no way, ad nauseum! You absolutely SHOULD
                              call dispose on OleDbConnection s, OleDbDataReader s and OleDbDataAdapte rs as
                              these are all connected data objects that may very well be holding pointers
                              to unmanaged data providers.
                              [color=blue]
                              >It doesn't hurt anything
                              > to call Dispose on them, it just does nothing useful (you *do* have to
                              > close them, and Dispose will call Close for you if necessary, but that's
                              > something else).[/color]

                              Again, sorry, no, nope!
                              [color=blue]
                              > But they all have visual representations that need to
                              > be disposed at design time, so they need to implement IDisposable.[/color]

                              Back to my first comment. Dispose is in absolutley no way related to the
                              visual design-time work done in VS.NET.


                              Comment

                              • Scott M.

                                #90
                                Re: Dispose Again!

                                Let me split some more hairs... I disagree that it is "not necessarily 'up
                                to the class user' to "call this method" if you are all interested in having
                                Dispose fire in a timely manner. Remember that without Dispose, we are at
                                the mercy of the GC for object clean up. The whole point of Dispose is to
                                avoid letting finalizes and the GC release unmanaged resources and for us to
                                take control of this. If we can't have deterministic finalization, we can
                                at least have deterministic clean-up.

                                This is the whole point behind Dispose. To even imply that the GC calls
                                dispose (when, in many situations it won't - even through the finalizer) is
                                mis-leading.


                                "Michael C#" <xyz@yomomma.co m> wrote in message
                                news:ulMfWMlLFH A.1284@TK2MSFTN GP14.phx.gbl...[color=blue]
                                > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                                > news:eYChnPcLFH A.904@tk2msftng p13.phx.gbl...[color=green]
                                >> The GC will never directly call Dispose! The GC will only directly call
                                >> Finalize! Finalize may or may not call Dispose. Normally Dispose &
                                >> Finalize will call a common routine.[/color]
                                >
                                > I think you mentioned "splitting hairs", Jay? Allow me to modify my
                                > statement to the following: The Dispose() method may be called from the
                                > Finalize() routine, which can be called by the GC; which would mean that
                                > it's not necessarily "up to the class user" to "call this method", which
                                > was the actual point.
                                >
                                > http://msdn.microsoft.com/library/de...izeDispose.asp
                                >
                                > Hope that helps.
                                >
                                > Thanks
                                >[/color]


                                Comment

                                Working...