Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. This is why I am starting to loathe programming

This is why I am starting to loathe programming

Scheduled Pinned Locked Moved The Lounge
phpvisual-studiocom
82 Posts 31 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leppie
    wrote on last edited by
    #1

    It's like the blind leading the blind.... http://stackoverflow.com/questions/2926869/c-do-you-need-to-dispose-of-objects-and-set-them-to-null/2926877#2926877[^] I think I will get similar responses from here too though :sigh:

    xacc.ide
    IronScheme - 1.0 RC 1 - out now!
    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

    R A D B P 15 Replies Last reply
    0
    • L leppie

      It's like the blind leading the blind.... http://stackoverflow.com/questions/2926869/c-do-you-need-to-dispose-of-objects-and-set-them-to-null/2926877#2926877[^] I think I will get similar responses from here too though :sigh:

      xacc.ide
      IronScheme - 1.0 RC 1 - out now!
      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

      R Offline
      R Offline
      realJSOP
      wrote on last edited by
      #2

      Well, I don't use "using" a lot, and I generally dispose and set to null when I'm done with an object. The GC also doesn't handle objects on the large heap.

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      A 1 Reply Last reply
      0
      • L leppie

        It's like the blind leading the blind.... http://stackoverflow.com/questions/2926869/c-do-you-need-to-dispose-of-objects-and-set-them-to-null/2926877#2926877[^] I think I will get similar responses from here too though :sigh:

        xacc.ide
        IronScheme - 1.0 RC 1 - out now!
        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #3

        Some people in the C# forum once informed me that not using "using" could lead to memory leaks due to the way .Net manages memory. They say that, because unmanaged resources are outside of the memory tracked by .Net, that memory can grow very large without triggering a garbage collection by .Net. So, maybe you have some objects with finalizers and such that make it the least often collected object. And maybe you only have a few of them and they don't take up much managed memory in .Net. However, they could still reference a ton of unmanaged memory, and .Net does not count that large amount of unmanaged memory when deciding whether or not to perform a garbage collection. That can lead to the memory growing out of hand... perhaps too far out of hand before .Net decides to do a garbage collection. Not sure if that's correct, but that's about what I think they were trying to convey to me.

        [Forum Guidelines]

        L F B 3 Replies Last reply
        0
        • R realJSOP

          Well, I don't use "using" a lot, and I generally dispose and set to null when I'm done with an object. The GC also doesn't handle objects on the large heap.

          .45 ACP - because shooting twice is just silly
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          John Simmons / outlaw programmer wrote:

          The GC also doesn't handle objects on the large heap.

          It does, but in a different way. The large object heap can suffer from fragmentation that causes it to grow beyond what it is actually being used to store, but objects on the LOH still get collected, eventually. I can't remember the details at the moment (I think the framgentation problem is because LOH objects aren't shifted about... they can never move from one position in the LOH to another position in the LOH, because moving large objects is a costly operation), but the GC does "handle" the LOH objects in the sense that they get collected automatically.

          [Forum Guidelines]

          L 1 Reply Last reply
          0
          • A AspDotNetDev

            Some people in the C# forum once informed me that not using "using" could lead to memory leaks due to the way .Net manages memory. They say that, because unmanaged resources are outside of the memory tracked by .Net, that memory can grow very large without triggering a garbage collection by .Net. So, maybe you have some objects with finalizers and such that make it the least often collected object. And maybe you only have a few of them and they don't take up much managed memory in .Net. However, they could still reference a ton of unmanaged memory, and .Net does not count that large amount of unmanaged memory when deciding whether or not to perform a garbage collection. That can lead to the memory growing out of hand... perhaps too far out of hand before .Net decides to do a garbage collection. Not sure if that's correct, but that's about what I think they were trying to convey to me.

            [Forum Guidelines]

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            The ratio of unmanaged memory to managed memory is pretty much insignificant, in 95%+ cases. Anyways, there are classes to inform the CLR about this, if it is excessive.

            xacc.ide
            IronScheme - 1.0 RC 1 - out now!
            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

            M 1 Reply Last reply
            0
            • L leppie

              It's like the blind leading the blind.... http://stackoverflow.com/questions/2926869/c-do-you-need-to-dispose-of-objects-and-set-them-to-null/2926877#2926877[^] I think I will get similar responses from here too though :sigh:

              xacc.ide
              IronScheme - 1.0 RC 1 - out now!
              ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

              D Offline
              D Offline
              Daniel Grunwald
              wrote on last edited by
              #6

              It's a bad idea to not dispose IDisposable objects. But the reasons given there are incorrect, it does not lead to memory leaks. But it does lead to excessive resource usage and potentially even to resource exhaustion (where resource != memory). Yeah and I don't visit StackOverflow anymore for this reason - popular myths get upvoted, correct answers usually get ignored.

              L 1 Reply Last reply
              0
              • D Daniel Grunwald

                It's a bad idea to not dispose IDisposable objects. But the reasons given there are incorrect, it does not lead to memory leaks. But it does lead to excessive resource usage and potentially even to resource exhaustion (where resource != memory). Yeah and I don't visit StackOverflow anymore for this reason - popular myths get upvoted, correct answers usually get ignored.

                L Offline
                L Offline
                leppie
                wrote on last edited by
                #7

                Daniel Grunwald wrote:

                But it does lead to excessive resource usage and potentially even to resource exhaustion (where resource != memory).

                That was my point too.

                Daniel Grunwald wrote:

                It's a bad idea to not dispose IDisposable objects.

                I know you should, but you dont have to, unless you want it to be deterministic.

                xacc.ide
                IronScheme - 1.0 RC 1 - out now!
                ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                P S Y 3 Replies Last reply
                0
                • L leppie

                  It's like the blind leading the blind.... http://stackoverflow.com/questions/2926869/c-do-you-need-to-dispose-of-objects-and-set-them-to-null/2926877#2926877[^] I think I will get similar responses from here too though :sigh:

                  xacc.ide
                  IronScheme - 1.0 RC 1 - out now!
                  ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                  B Offline
                  B Offline
                  Brady Kelly
                  wrote on last edited by
                  #8

                  I think I can avoid a downvote or two, on my way now. :cool:

                  1 Reply Last reply
                  0
                  • L leppie

                    It's like the blind leading the blind.... http://stackoverflow.com/questions/2926869/c-do-you-need-to-dispose-of-objects-and-set-them-to-null/2926877#2926877[^] I think I will get similar responses from here too though :sigh:

                    xacc.ide
                    IronScheme - 1.0 RC 1 - out now!
                    ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                    P Offline
                    P Offline
                    peterchen
                    wrote on last edited by
                    #9

                    SO WHERE IS YOUR UNMANAGED RESOURCE?

                    Agh! Reality! My Archnemesis![^]
                    | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server.

                    B 1 Reply Last reply
                    0
                    • P peterchen

                      SO WHERE IS YOUR UNMANAGED RESOURCE?

                      Agh! Reality! My Archnemesis![^]
                      | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server.

                      B Offline
                      B Offline
                      Brady Kelly
                      wrote on last edited by
                      #10

                      peterchen wrote:

                      SO WHERE IS YOUR UNMANAGED RESOURCE?

                      if it was managed I'd know where it was, but my management of my resources (e.g. cash) is notoriously bad. I'd make a good accountant, but no great fund manager.

                      1 Reply Last reply
                      0
                      • L leppie

                        Daniel Grunwald wrote:

                        But it does lead to excessive resource usage and potentially even to resource exhaustion (where resource != memory).

                        That was my point too.

                        Daniel Grunwald wrote:

                        It's a bad idea to not dispose IDisposable objects.

                        I know you should, but you dont have to, unless you want it to be deterministic.

                        xacc.ide
                        IronScheme - 1.0 RC 1 - out now!
                        ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                        P Offline
                        P Offline
                        peterchen
                        wrote on last edited by
                        #11

                        By implementing IDisposable, the class creator explicitely told you to call Dispose(). If the documentation of a class said "You need to call Init() before using an instance of this class", would you reply with "Ah, I don#t feel like it today"?

                        Agh! Reality! My Archnemesis![^]
                        | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server.

                        L C 2 Replies Last reply
                        0
                        • P peterchen

                          By implementing IDisposable, the class creator explicitely told you to call Dispose(). If the documentation of a class said "You need to call Init() before using an instance of this class", would you reply with "Ah, I don#t feel like it today"?

                          Agh! Reality! My Archnemesis![^]
                          | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server.

                          L Offline
                          L Offline
                          leppie
                          wrote on last edited by
                          #12

                          peterchen wrote:

                          the class creator explicitely told you to call Dispose().

                          No, he actually said: 'If you want to cleanup the resources immediately, then call Dispose(), but if you forget or dont want to, I'll do it anyways when the object finalizer is called.'

                          xacc.ide
                          IronScheme - 1.0 RC 1 - out now!
                          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                          P P F X 4 Replies Last reply
                          0
                          • A AspDotNetDev

                            John Simmons / outlaw programmer wrote:

                            The GC also doesn't handle objects on the large heap.

                            It does, but in a different way. The large object heap can suffer from fragmentation that causes it to grow beyond what it is actually being used to store, but objects on the LOH still get collected, eventually. I can't remember the details at the moment (I think the framgentation problem is because LOH objects aren't shifted about... they can never move from one position in the LOH to another position in the LOH, because moving large objects is a costly operation), but the GC does "handle" the LOH objects in the sense that they get collected automatically.

                            [Forum Guidelines]

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #13

                            yep, the difference is the move cost is high, therefore moves are avoided and that results in a fragmentation risk. But it isn't as black-and-white as it used to be; I have "frag demonstration code" that used to always work long ago (i.e. reach an intended out of memory situation easily), and more recently fails; I've never seen an improvement in LOH treadment documented though. :)

                            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                            I only read formatted code with indentation, so please use PRE tags for code snippets.


                            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                            1 Reply Last reply
                            0
                            • L leppie

                              It's like the blind leading the blind.... http://stackoverflow.com/questions/2926869/c-do-you-need-to-dispose-of-objects-and-set-them-to-null/2926877#2926877[^] I think I will get similar responses from here too though :sigh:

                              xacc.ide
                              IronScheme - 1.0 RC 1 - out now!
                              ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                              L Offline
                              L Offline
                              Luc Pattyn
                              wrote on last edited by
                              #14

                              leppie wrote:

                              I think I will get similar responses from here too though

                              I for one would set you straight if you were to publish such statements in one of CP's programming forums. :|

                              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                              I only read formatted code with indentation, so please use PRE tags for code snippets.


                              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                              1 Reply Last reply
                              0
                              • L leppie

                                It's like the blind leading the blind.... http://stackoverflow.com/questions/2926869/c-do-you-need-to-dispose-of-objects-and-set-them-to-null/2926877#2926877[^] I think I will get similar responses from here too though :sigh:

                                xacc.ide
                                IronScheme - 1.0 RC 1 - out now!
                                ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #15

                                A while back I looked at manual garbage collection and it simply wasn't worthwhile. You would have to be doing something very drastic to consider it.

                                Join the cool kids - Come fold with us[^]

                                1 Reply Last reply
                                0
                                • L leppie

                                  peterchen wrote:

                                  the class creator explicitely told you to call Dispose().

                                  No, he actually said: 'If you want to cleanup the resources immediately, then call Dispose(), but if you forget or dont want to, I'll do it anyways when the object finalizer is called.'

                                  xacc.ide
                                  IronScheme - 1.0 RC 1 - out now!
                                  ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                                  P Offline
                                  P Offline
                                  PIEBALDconsult
                                  wrote on last edited by
                                  #16

                                  Hear hear! I implement IDisposable on a lot of classes that don't really need it, because the using pattern is so good at letting the reader clearly see the lifetime of an instance. I dislike finding that a class I want to use can't be used in a using statement. In my opinion, object should have a virtual do-nothing Dispose method so that any class or struct can be used with the using statement. (We would therefore not need the IDisposable interface.)

                                  V 1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    Hear hear! I implement IDisposable on a lot of classes that don't really need it, because the using pattern is so good at letting the reader clearly see the lifetime of an instance. I dislike finding that a class I want to use can't be used in a using statement. In my opinion, object should have a virtual do-nothing Dispose method so that any class or struct can be used with the using statement. (We would therefore not need the IDisposable interface.)

                                    V Offline
                                    V Offline
                                    Vikram A Punathambekar
                                    wrote on last edited by
                                    #17

                                    PIEBALDconsult wrote:

                                    In my opinion, object should have a virtual do-nothing Dispose method so that any class or struct can be used with the using statement. (We would therefore not need the IDisposable interface.)

                                    For everybody, not just piebald: it's been well over 1.5 years since I wrote C# production code, so take my words with a large dose of scepticism. I agree with Piebald here. Any gurus care to explain why this isn't the case?

                                    Cheers, Vikram. (Got my troika of CCCs!)

                                    D T M 3 Replies Last reply
                                    0
                                    • L leppie

                                      peterchen wrote:

                                      the class creator explicitely told you to call Dispose().

                                      No, he actually said: 'If you want to cleanup the resources immediately, then call Dispose(), but if you forget or dont want to, I'll do it anyways when the object finalizer is called.'

                                      xacc.ide
                                      IronScheme - 1.0 RC 1 - out now!
                                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                                      P Offline
                                      P Offline
                                      peterchen
                                      wrote on last edited by
                                      #18

                                      leppie wrote:

                                      when

                                      You misspelled "if". I just don't like the default of "your" rule. "Call Dispose unless you know what you are doing" would be ok. "Don't call Dispose unless, umm, you feel like it" is not. Also, Having to call Dispose may affect code structure, which means figuring out later you have to call it may require major changes. [edit] as an example: Omitting Disposal of a resource holdign a file handle: You: "It's ok, we can have zillions of open file handles in windows". Me: "The file handle may remain open forever. Even if the user closed the file, he can't move or modify it in another program - or instance of this program - because we still keep the file handle open. It's one of those completely unecessary, insanely annoying bugs."

                                      Agh! Reality! My Archnemesis![^]
                                      | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server.

                                      L 1 Reply Last reply
                                      0
                                      • V Vikram A Punathambekar

                                        PIEBALDconsult wrote:

                                        In my opinion, object should have a virtual do-nothing Dispose method so that any class or struct can be used with the using statement. (We would therefore not need the IDisposable interface.)

                                        For everybody, not just piebald: it's been well over 1.5 years since I wrote C# production code, so take my words with a large dose of scepticism. I agree with Piebald here. Any gurus care to explain why this isn't the case?

                                        Cheers, Vikram. (Got my troika of CCCs!)

                                        D Offline
                                        D Offline
                                        Daniel Grunwald
                                        wrote on last edited by
                                        #19

                                        C# is a garbage collected language. If you want explicit memory management for all object, use C++.

                                        P V 2 Replies Last reply
                                        0
                                        • D Daniel Grunwald

                                          C# is a garbage collected language. If you want explicit memory management for all object, use C++.

                                          P Offline
                                          P Offline
                                          PIEBALDconsult
                                          wrote on last edited by
                                          #20

                                          Daniel Grunwald wrote:

                                          C# is a garbage collected language

                                          Exactly. It's not about memory management.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups