Dispose Again!

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

    #31
    Re: Dispose Again!

    I'm not so sure about that Cor. I have read many articles and seen many
    posts that suggest that the DataAdapter, DataReader and Connection objects
    SHOULD be disposed.


    "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
    news:%232kI3OKL FHA.904@tk2msft ngp13.phx.gbl.. .[color=blue]
    > Dennis,
    >
    > There is no need to dispose any object of system.data.
    >
    > I have written a while that the exception on this is the connection, that
    > is used for the connection pooling what was consequently told by Angel in
    > the AdoNet newsgroup and that was done something with the fysical
    > connection string (not the code) in a kind of overriden function from
    > dispose.
    >
    > Because this message below in that newsgroup (it is not the first) I
    > become confused again however keep that dispose for the connection string.
    > The other objects does not need a dispose. There the dispose is only
    > because the method is inherited from components from which all system.data
    > classes inherits.
    >
    > http://groups-beta.google.com/group/...11c0671640ad38
    >
    > I hope this give some idea's
    >
    > Cor
    >[/color]


    Comment

    • Michael C#

      #32
      Re: Dispose Again!

      If I understand Dispose() correctly, it simply forces the .NET framework to
      mark an object for Garbage Collection. As I look at the "Windows Forms
      Designer generated" Dispose() method of a Form, it is appears that the Form
      itself performs Dispose() on all the Form's components, which if I'm not
      mistaken, would include labels, etc.

      As I understand it, Dispose() does not force a Garbage Collection, so that
      should not be an issue. Is there any real benefit to *not* calling
      Dispose() on objects that expose it once you know that they are no longer
      needed (such as a SqlCommand), or is there a complex matrix of rules for
      when and when not to use Dispose() that should be referenced every time you
      create a new object?

      "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
      news:ulwOZpFLFH A.244@TK2MSFTNG P12.phx.gbl...[color=blue]
      > Dennis,
      >
      > When you inherit from Components than there is already Idispose
      > implemented in the base class. (By instance all classes in Sytem.Data and
      > System.Windows. Forms.Control inherit from Components) You just have to do
      > nothing because it is done by the base class when that class goes out of
      > scope. Therefore I inherit from components when I make a class from which
      > I have slightly the idea that it has unmanaged resources in it.
      >
      > http://search.microsoft.com/search/r...&c=0&s=1&swc=0
      >
      > IComponent implements IDisposable for when you are searching that.
      >
      > I hope this helps,
      >
      > Cor
      >[/color]


      Comment

      • Michael C#

        #33
        Re: Dispose Again!

        If I understand Dispose() correctly, it simply forces the .NET framework to
        mark an object for Garbage Collection. As I look at the "Windows Forms
        Designer generated" Dispose() method of a Form, it is appears that the Form
        itself performs Dispose() on all the Form's components, which if I'm not
        mistaken, would include labels, etc.

        As I understand it, Dispose() does not force a Garbage Collection, so that
        should not be an issue. Is there any real benefit to *not* calling
        Dispose() on objects that expose it once you know that they are no longer
        needed (such as a SqlCommand), or is there a complex matrix of rules for
        when and when not to use Dispose() that should be referenced every time you
        create a new object?

        "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
        news:ulwOZpFLFH A.244@TK2MSFTNG P12.phx.gbl...[color=blue]
        > Dennis,
        >
        > When you inherit from Components than there is already Idispose
        > implemented in the base class. (By instance all classes in Sytem.Data and
        > System.Windows. Forms.Control inherit from Components) You just have to do
        > nothing because it is done by the base class when that class goes out of
        > scope. Therefore I inherit from components when I make a class from which
        > I have slightly the idea that it has unmanaged resources in it.
        >
        > http://search.microsoft.com/search/r...&c=0&s=1&swc=0
        >
        > IComponent implements IDisposable for when you are searching that.
        >
        > I hope this helps,
        >
        > Cor
        >[/color]


        Comment

        • Jay B. Harlow [MVP - Outlook]

          #34
          Re: Dispose Again!

          Cor,[color=blue]
          > There is no need to dispose any object of system.data.[/color]
          Where do you get that in the link you gave???

          If anything the link you gave says you need to call Dispose (or Close).

          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.Odb c,
          System.Data.Ole Db, System.Data.Sql Client, and System.Data.Ora cleClient! As
          they all contain classes that deal with "external" (aka unmanaged) resource.

          Hope this helps
          Jay

          "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
          news:%232kI3OKL FHA.904@tk2msft ngp13.phx.gbl.. .[color=blue]
          > Dennis,
          >
          > There is no need to dispose any object of system.data.
          >
          > I have written a while that the exception on this is the connection, that
          > is used for the connection pooling what was consequently told by Angel in
          > the AdoNet newsgroup and that was done something with the fysical
          > connection string (not the code) in a kind of overriden function from
          > dispose.
          >
          > Because this message below in that newsgroup (it is not the first) I
          > become confused again however keep that dispose for the connection string.
          > The other objects does not need a dispose. There the dispose is only
          > because the method is inherited from components from which all system.data
          > classes inherits.
          >
          > http://groups-beta.google.com/group/...11c0671640ad38
          >
          > I hope this give some idea's
          >
          > Cor
          >[/color]


          Comment

          • Jay B. Harlow [MVP - Outlook]

            #35
            Re: Dispose Again!

            Cor,[color=blue]
            > There is no need to dispose any object of system.data.[/color]
            Where do you get that in the link you gave???

            If anything the link you gave says you need to call Dispose (or Close).

            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.Odb c,
            System.Data.Ole Db, System.Data.Sql Client, and System.Data.Ora cleClient! As
            they all contain classes that deal with "external" (aka unmanaged) resource.

            Hope this helps
            Jay

            "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
            news:%232kI3OKL FHA.904@tk2msft ngp13.phx.gbl.. .[color=blue]
            > Dennis,
            >
            > There is no need to dispose any object of system.data.
            >
            > I have written a while that the exception on this is the connection, that
            > is used for the connection pooling what was consequently told by Angel in
            > the AdoNet newsgroup and that was done something with the fysical
            > connection string (not the code) in a kind of overriden function from
            > dispose.
            >
            > Because this message below in that newsgroup (it is not the first) I
            > become confused again however keep that dispose for the connection string.
            > The other objects does not need a dispose. There the dispose is only
            > because the method is inherited from components from which all system.data
            > classes inherits.
            >
            > http://groups-beta.google.com/group/...11c0671640ad38
            >
            > I hope this give some idea's
            >
            > Cor
            >[/color]


            Comment

            • Jay B. Harlow [MVP - Outlook]

              #36
              Re: Dispose Again!

              Dennis,[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]
              Without "knowing" for certain that IMHO is the "best" practice.

              The "better safe then sorry" pattern. :-)

              Hope this helps
              Jay


              "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
              news:8EAC667D-FAEC-4AC9-AA94-68FA1BE79D29@mi crosoft.com...[color=blue]
              > Thanks to all. I am beginning to understand a little of what the dispose
              > is
              > all about and all this discussion certainly helps me and I think a lot of
              > people using VB.Net. 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!"
              >
              > "Cor Ligthert" wrote:
              >[color=green]
              >> Dennis,
              >>
              >> When you inherit from Components than there is already Idispose
              >> implemented
              >> in the base class. (By instance all classes in Sytem.Data and
              >> System.Windows. Forms.Control inherit from Components) You just have to
              >> do
              >> nothing because it is done by the base class when that class goes out of
              >> scope. Therefore I inherit from components when I make a class from which
              >> I
              >> have slightly the idea that it has unmanaged resources in it.
              >>
              >> http://search.microsoft.com/search/r...&c=0&s=1&swc=0
              >>
              >> IComponent implements IDisposable for when you are searching that.
              >>
              >> I hope this helps,
              >>
              >> Cor
              >>
              >>
              >>[/color][/color]


              Comment

              • Jay B. Harlow [MVP - Outlook]

                #37
                Re: Dispose Again!

                Dennis,[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]
                Without "knowing" for certain that IMHO is the "best" practice.

                The "better safe then sorry" pattern. :-)

                Hope this helps
                Jay


                "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
                news:8EAC667D-FAEC-4AC9-AA94-68FA1BE79D29@mi crosoft.com...[color=blue]
                > Thanks to all. I am beginning to understand a little of what the dispose
                > is
                > all about and all this discussion certainly helps me and I think a lot of
                > people using VB.Net. 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!"
                >
                > "Cor Ligthert" wrote:
                >[color=green]
                >> Dennis,
                >>
                >> When you inherit from Components than there is already Idispose
                >> implemented
                >> in the base class. (By instance all classes in Sytem.Data and
                >> System.Windows. Forms.Control inherit from Components) You just have to
                >> do
                >> nothing because it is done by the base class when that class goes out of
                >> scope. Therefore I inherit from components when I make a class from which
                >> I
                >> have slightly the idea that it has unmanaged resources in it.
                >>
                >> http://search.microsoft.com/search/r...&c=0&s=1&swc=0
                >>
                >> IComponent implements IDisposable for when you are searching that.
                >>
                >> I hope this helps,
                >>
                >> Cor
                >>
                >>
                >>[/color][/color]


                Comment

                • Scott M.

                  #38
                  Re: Dispose Again!

                  > If I understand Dispose() correctly, it simply forces the .NET framework[color=blue]
                  > to mark an object for Garbage Collection.[/color]

                  Not necessarially. An object is marked for collection when nothing is
                  pointing at it any longer.
                  [color=blue]
                  >As I look at the "Windows Forms Designer generated" Dispose() method of a
                  >Form, it is appears that the Form itself performs Dispose() on all the
                  >Form's components, which if I'm not mistaken, would include labels, etc.[/color]

                  Correct, but since the designer has no idea what kind of controls you'll be
                  putting on your form, it takes the better safe than sorry approach and
                  disposes your controls (even if they don't need to be disposed).
                  [color=blue]
                  > As I understand it, Dispose() does not force a Garbage Collection, so that
                  > should not be an issue.[/color]

                  Correct.
                  [color=blue]
                  > Is there any real benefit to *not* calling Dispose() on objects that
                  > expose it once you know that they are no longer needed (such as a
                  > SqlCommand), or is there a complex matrix of rules for when and when not
                  > to use Dispose() that should be referenced every time you create a new
                  > object?[/color]

                  Calling Dispose on a label wouldn't *hurt* anything, but it would cause your
                  application to perform additional tasks that may not be needed. So, it
                  could conceivably slow an application down to be calling Dispose on
                  everything, rather than just the things that really need it.



                  [color=blue]
                  >
                  > "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                  > news:ulwOZpFLFH A.244@TK2MSFTNG P12.phx.gbl...[color=green]
                  >> Dennis,
                  >>
                  >> When you inherit from Components than there is already Idispose
                  >> implemented in the base class. (By instance all classes in Sytem.Data and
                  >> System.Windows. Forms.Control inherit from Components) You just have to
                  >> do nothing because it is done by the base class when that class goes out
                  >> of scope. Therefore I inherit from components when I make a class from
                  >> which I have slightly the idea that it has unmanaged resources in it.
                  >>
                  >> http://search.microsoft.com/search/r...&c=0&s=1&swc=0
                  >>
                  >> IComponent implements IDisposable for when you are searching that.
                  >>
                  >> I hope this helps,
                  >>
                  >> Cor
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  • Scott M.

                    #39
                    Re: Dispose Again!

                    > If I understand Dispose() correctly, it simply forces the .NET framework[color=blue]
                    > to mark an object for Garbage Collection.[/color]

                    Not necessarially. An object is marked for collection when nothing is
                    pointing at it any longer.
                    [color=blue]
                    >As I look at the "Windows Forms Designer generated" Dispose() method of a
                    >Form, it is appears that the Form itself performs Dispose() on all the
                    >Form's components, which if I'm not mistaken, would include labels, etc.[/color]

                    Correct, but since the designer has no idea what kind of controls you'll be
                    putting on your form, it takes the better safe than sorry approach and
                    disposes your controls (even if they don't need to be disposed).
                    [color=blue]
                    > As I understand it, Dispose() does not force a Garbage Collection, so that
                    > should not be an issue.[/color]

                    Correct.
                    [color=blue]
                    > Is there any real benefit to *not* calling Dispose() on objects that
                    > expose it once you know that they are no longer needed (such as a
                    > SqlCommand), or is there a complex matrix of rules for when and when not
                    > to use Dispose() that should be referenced every time you create a new
                    > object?[/color]

                    Calling Dispose on a label wouldn't *hurt* anything, but it would cause your
                    application to perform additional tasks that may not be needed. So, it
                    could conceivably slow an application down to be calling Dispose on
                    everything, rather than just the things that really need it.



                    [color=blue]
                    >
                    > "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                    > news:ulwOZpFLFH A.244@TK2MSFTNG P12.phx.gbl...[color=green]
                    >> Dennis,
                    >>
                    >> When you inherit from Components than there is already Idispose
                    >> implemented in the base class. (By instance all classes in Sytem.Data and
                    >> System.Windows. Forms.Control inherit from Components) You just have to
                    >> do nothing because it is done by the base class when that class goes out
                    >> of scope. Therefore I inherit from components when I make a class from
                    >> which I have slightly the idea that it has unmanaged resources in it.
                    >>
                    >> http://search.microsoft.com/search/r...&c=0&s=1&swc=0
                    >>
                    >> IComponent implements IDisposable for when you are searching that.
                    >>
                    >> I hope this helps,
                    >>
                    >> Cor
                    >>[/color]
                    >
                    >[/color]


                    Comment

                    • Cor Ligthert

                      #40
                      Re: Dispose Again!

                      Jay,

                      What has it for sense to dispose every individual part of a class when the
                      base class does the dispose?
                      [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.Odb c, System.Data.Ole Db, System.Data.Sql Client, and
                      > System.Data.Ora cleClient! As they all contain classes that deal with
                      > "external" (aka unmanaged) resource.[/color]

                      Do you mean that I understand this page wrong?



                      Comment

                      • Cor Ligthert

                        #41
                        Re: Dispose Again!

                        Jay,

                        What has it for sense to dispose every individual part of a class when the
                        base class does the dispose?
                        [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.Odb c, System.Data.Ole Db, System.Data.Sql Client, and
                        > System.Data.Ora cleClient! As they all contain classes that deal with
                        > "external" (aka unmanaged) resource.[/color]

                        Do you mean that I understand this page wrong?



                        Comment

                        • Cor Ligthert

                          #42
                          Re: Dispose Again!




                          Comment

                          • Cor Ligthert

                            #43
                            Re: Dispose Again!




                            Comment

                            • Dennis

                              #44
                              Re: Dispose Again!

                              This is the thrid or fourth different question I've posed on this newsgroup
                              about dispose and really enjoy the "confusion" . If Microsoft is listening,
                              then they should step up and "in plan English" explain when to dispose and
                              when not to. They give hints and sometimes even state that something needs
                              to be disposed in their MSDN help but I sure wish they'd put this like in the
                              header of the help sheets such as "Dispose needed - Yes/No"

                              "Scott M." wrote:
                              [color=blue][color=green]
                              > > If I understand Dispose() correctly, it simply forces the .NET framework
                              > > to mark an object for Garbage Collection.[/color]
                              >
                              > Not necessarially. An object is marked for collection when nothing is
                              > pointing at it any longer.
                              >[color=green]
                              > >As I look at the "Windows Forms Designer generated" Dispose() method of a
                              > >Form, it is appears that the Form itself performs Dispose() on all the
                              > >Form's components, which if I'm not mistaken, would include labels, etc.[/color]
                              >
                              > Correct, but since the designer has no idea what kind of controls you'll be
                              > putting on your form, it takes the better safe than sorry approach and
                              > disposes your controls (even if they don't need to be disposed).
                              >[color=green]
                              > > As I understand it, Dispose() does not force a Garbage Collection, so that
                              > > should not be an issue.[/color]
                              >
                              > Correct.
                              >[color=green]
                              > > Is there any real benefit to *not* calling Dispose() on objects that
                              > > expose it once you know that they are no longer needed (such as a
                              > > SqlCommand), or is there a complex matrix of rules for when and when not
                              > > to use Dispose() that should be referenced every time you create a new
                              > > object?[/color]
                              >
                              > Calling Dispose on a label wouldn't *hurt* anything, but it would cause your
                              > application to perform additional tasks that may not be needed. So, it
                              > could conceivably slow an application down to be calling Dispose on
                              > everything, rather than just the things that really need it.
                              >
                              >
                              >
                              >[color=green]
                              > >
                              > > "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                              > > news:ulwOZpFLFH A.244@TK2MSFTNG P12.phx.gbl...[color=darkred]
                              > >> Dennis,
                              > >>
                              > >> When you inherit from Components than there is already Idispose
                              > >> implemented in the base class. (By instance all classes in Sytem.Data and
                              > >> System.Windows. Forms.Control inherit from Components) You just have to
                              > >> do nothing because it is done by the base class when that class goes out
                              > >> of scope. Therefore I inherit from components when I make a class from
                              > >> which I have slightly the idea that it has unmanaged resources in it.
                              > >>
                              > >> http://search.microsoft.com/search/r...&c=0&s=1&swc=0
                              > >>
                              > >> IComponent implements IDisposable for when you are searching that.
                              > >>
                              > >> I hope this helps,
                              > >>
                              > >> Cor
                              > >>[/color]
                              > >
                              > >[/color]
                              >
                              >
                              >[/color]

                              Comment

                              • Dennis

                                #45
                                Re: Dispose Again!

                                This is the thrid or fourth different question I've posed on this newsgroup
                                about dispose and really enjoy the "confusion" . If Microsoft is listening,
                                then they should step up and "in plan English" explain when to dispose and
                                when not to. They give hints and sometimes even state that something needs
                                to be disposed in their MSDN help but I sure wish they'd put this like in the
                                header of the help sheets such as "Dispose needed - Yes/No"

                                "Scott M." wrote:
                                [color=blue][color=green]
                                > > If I understand Dispose() correctly, it simply forces the .NET framework
                                > > to mark an object for Garbage Collection.[/color]
                                >
                                > Not necessarially. An object is marked for collection when nothing is
                                > pointing at it any longer.
                                >[color=green]
                                > >As I look at the "Windows Forms Designer generated" Dispose() method of a
                                > >Form, it is appears that the Form itself performs Dispose() on all the
                                > >Form's components, which if I'm not mistaken, would include labels, etc.[/color]
                                >
                                > Correct, but since the designer has no idea what kind of controls you'll be
                                > putting on your form, it takes the better safe than sorry approach and
                                > disposes your controls (even if they don't need to be disposed).
                                >[color=green]
                                > > As I understand it, Dispose() does not force a Garbage Collection, so that
                                > > should not be an issue.[/color]
                                >
                                > Correct.
                                >[color=green]
                                > > Is there any real benefit to *not* calling Dispose() on objects that
                                > > expose it once you know that they are no longer needed (such as a
                                > > SqlCommand), or is there a complex matrix of rules for when and when not
                                > > to use Dispose() that should be referenced every time you create a new
                                > > object?[/color]
                                >
                                > Calling Dispose on a label wouldn't *hurt* anything, but it would cause your
                                > application to perform additional tasks that may not be needed. So, it
                                > could conceivably slow an application down to be calling Dispose on
                                > everything, rather than just the things that really need it.
                                >
                                >
                                >
                                >[color=green]
                                > >
                                > > "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                                > > news:ulwOZpFLFH A.244@TK2MSFTNG P12.phx.gbl...[color=darkred]
                                > >> Dennis,
                                > >>
                                > >> When you inherit from Components than there is already Idispose
                                > >> implemented in the base class. (By instance all classes in Sytem.Data and
                                > >> System.Windows. Forms.Control inherit from Components) You just have to
                                > >> do nothing because it is done by the base class when that class goes out
                                > >> of scope. Therefore I inherit from components when I make a class from
                                > >> which I have slightly the idea that it has unmanaged resources in it.
                                > >>
                                > >> http://search.microsoft.com/search/r...&c=0&s=1&swc=0
                                > >>
                                > >> IComponent implements IDisposable for when you are searching that.
                                > >>
                                > >> I hope this helps,
                                > >>
                                > >> Cor
                                > >>[/color]
                                > >
                                > >[/color]
                                >
                                >
                                >[/color]

                                Comment

                                Working...