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. Windows Service Rant

Windows Service Rant

Scheduled Pinned Locked Moved The Lounge
csharpcomtoolsperformancequestion
21 Posts 13 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.
  • E Ennis Ray Lynch Jr

    Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

    Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

    S Offline
    S Offline
    Steve Westbrook
    wrote on last edited by
    #3

    Ennis Ray Lynch, Jr. wrote:

    eh, what can you do?

    GC.Collect()

    T E N 3 Replies Last reply
    0
    • E Ennis Ray Lynch Jr

      Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

      Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

      T Offline
      T Offline
      Todd Smith
      wrote on last edited by
      #4

      You could always force a call to the garbage collector.

      Todd Smith

      1 Reply Last reply
      0
      • S Steve Westbrook

        Ennis Ray Lynch, Jr. wrote:

        eh, what can you do?

        GC.Collect()

        T Offline
        T Offline
        ToddHileHoffer
        wrote on last edited by
        #5

        I was going to write the same thing, but I thought surely the OP already tried this.

        I didn't get any requirements for the signature

        1 Reply Last reply
        0
        • S Steve Westbrook

          Ennis Ray Lynch, Jr. wrote:

          eh, what can you do?

          GC.Collect()

          E Offline
          E Offline
          Ennis Ray Lynch Jr
          wrote on last edited by
          #6

          http://blogs.msdn.com/ricom/archive/2004/11/29/271829.aspx[^]

          Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

          1 Reply Last reply
          0
          • E Ennis Ray Lynch Jr

            Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

            Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

            M Offline
            M Offline
            Marc Clifton
            wrote on last edited by
            #7

            Ennis Ray Lynch, Jr. wrote:

            Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected)

            I don't think that would be expected. A local variable would be declared on the stack, and you should not see any visible change to allocated memory, so something seems fishy. I've written .NET services and I've seen this behavior. As other have suggested, try GC.Collect, not as the permanent solution, but to see if garbage collection actually does fix the problem. It seems to me there's something else going on, and GC'ing won't actually affect anything. Marc

            A 1 Reply Last reply
            0
            • E Ennis Ray Lynch Jr

              Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

              Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

              E Offline
              E Offline
              Electron Shepherd
              wrote on last edited by
              #8

              Two thoughts: 1) Is the service code somehow preventing the garbage collection running? 2) See http://blogs.msdn.com/willbar/archive/2009/12/17/tracking-down-a-net-windows-service-memory-leak.aspx[^]

              Server and Network Monitoring

              1 Reply Last reply
              0
              • M Marc Clifton

                Ennis Ray Lynch, Jr. wrote:

                Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected)

                I don't think that would be expected. A local variable would be declared on the stack, and you should not see any visible change to allocated memory, so something seems fishy. I've written .NET services and I've seen this behavior. As other have suggested, try GC.Collect, not as the permanent solution, but to see if garbage collection actually does fix the problem. It seems to me there's something else going on, and GC'ing won't actually affect anything. Marc

                A Offline
                A Offline
                Andy Brummer
                wrote on last edited by
                #9

                Marc Clifton wrote:

                I don't think that would be expected. A local variable would be declared on the stack

                Only if they are structs built out of structs. Classes are always allocated on the heap with a reference from the stack.

                I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

                M 1 Reply Last reply
                0
                • S Steve Westbrook

                  Ennis Ray Lynch, Jr. wrote:

                  eh, what can you do?

                  GC.Collect()

                  N Offline
                  N Offline
                  Nemanja Trifunovic
                  wrote on last edited by
                  #10

                  Steve Westbrook wrote:

                  GC.Collect()

                  Won't help :)

                  utf8-cpp

                  1 Reply Last reply
                  0
                  • E Ennis Ray Lynch Jr

                    Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

                    Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

                    N Offline
                    N Offline
                    Nemanja Trifunovic
                    wrote on last edited by
                    #11

                    Ennis Ray Lynch, Jr. wrote:

                    Looks like I may have a use, after all, for my object pool code.

                    That.

                    utf8-cpp

                    1 Reply Last reply
                    0
                    • A Andy Brummer

                      Marc Clifton wrote:

                      I don't think that would be expected. A local variable would be declared on the stack

                      Only if they are structs built out of structs. Classes are always allocated on the heap with a reference from the stack.

                      I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

                      M Offline
                      M Offline
                      Marc Clifton
                      wrote on last edited by
                      #12

                      Andy Brummer wrote:

                      Classes are always allocated on the heap with a reference from the stack.

                      Yeah, I know. I guess when he said "local variable", I was thinking something like int foo;, not A foo=new A(); Marc

                      A 1 Reply Last reply
                      0
                      • E Ennis Ray Lynch Jr

                        Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

                        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

                        A Offline
                        A Offline
                        Andy Brummer
                        wrote on last edited by
                        #13

                        Check all the .net memory performance counters for the process. If you have a dangling reference then gen 1 and 2 will be growing. If it is just objects which are quickly released then objects should mostly live in gen0. Also if you are allocating large arrays, they can be allocated on the large object heap which has different cleanup behavior. I've allocated roughly 10 100 meg arrays causing the process to use an extra gig. Calling collect after the array went out of scope caused constant memory use, and then an object cache fixed it for final production use.

                        I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

                        1 Reply Last reply
                        0
                        • M Marc Clifton

                          Andy Brummer wrote:

                          Classes are always allocated on the heap with a reference from the stack.

                          Yeah, I know. I guess when he said "local variable", I was thinking something like int foo;, not A foo=new A(); Marc

                          A Offline
                          A Offline
                          Andy Brummer
                          wrote on last edited by
                          #14

                          I Did a double take after replying as I didn't see it was you when I answered. Kinda figured you were pretty familiar with the whole .net memory management thing. :laugh:

                          I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

                          M 1 Reply Last reply
                          0
                          • A Andy Brummer

                            I Did a double take after replying as I didn't see it was you when I answered. Kinda figured you were pretty familiar with the whole .net memory management thing. :laugh:

                            I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

                            M Offline
                            M Offline
                            Marc Clifton
                            wrote on last edited by
                            #15

                            Andy Brummer wrote:

                            Kinda figured you were pretty familiar with the whole .net memory management thing.

                            Yeah, after your reply, I figured I better CMA quickly! Marc

                            1 Reply Last reply
                            0
                            • E Ennis Ray Lynch Jr

                              Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

                              Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

                              J Offline
                              J Offline
                              J Dunlap
                              wrote on last edited by
                              #16

                              Sounds like you have a good use for a memory profiler... a good one will give you info about held, reachable, and finalized objects as well as a lot of other memory details. I like to use JetBrains dotTrace[^]. * *I'm not associated with JetBrains in any way, just a happy user. Well ok, I did happen to get dotTrace free when I was a Microsoft MVP.

                              1 Reply Last reply
                              0
                              • realJSOPR realJSOP

                                You could just null the unused objects and maintain a count of them, and when the count meets a preset limit, call the GC on them.

                                .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

                                S Offline
                                S Offline
                                Single Step Debugger
                                wrote on last edited by
                                #17

                                They call this "smart pointers". ;P

                                The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                                1 Reply Last reply
                                0
                                • E Ennis Ray Lynch Jr

                                  Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

                                  Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

                                  P Offline
                                  P Offline
                                  Pete OHanlon
                                  wrote on last edited by
                                  #18

                                  Take a look at using Weak references[^]. It could be that you have something being held that could easily be released, such as an event.

                                  "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                                  As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                                  My blog | My articles | MoXAML PowerToys | Onyx

                                  1 Reply Last reply
                                  0
                                  • E Ennis Ray Lynch Jr

                                    Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

                                    Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

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

                                    You want to use less stack space? (OK that is a programming question) Add the following to you app.config (in the Runtime section):

                                    <disableCommitThreadStack enabled="1" />

                                    You might want to call GC.Collect occasionally too if you have plenty of spare memory.

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

                                    1 Reply Last reply
                                    0
                                    • E Ennis Ray Lynch Jr

                                      Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

                                      Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

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

                                      Ennis Ray Lynch, Jr. wrote:

                                      Turns out every time a local variable is declared (even a base value type) the memory usage would go up

                                      BTW, it sounds like you are boxing the valuetype 'instances' (actually values) (which does have it's roles in a very few corners of the CS application space), maybe it is time to explore generics ;P

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

                                      1 Reply Last reply
                                      0
                                      • E Ennis Ray Lynch Jr

                                        Actually this is probably a .NET rant. My newly developed service was slowly but surely using more and more memory. Surely, it couldn't be a memory leak because only managed objects where used! Turns out every time a local variable is declared (even a base value type) the memory usage would go up (o.k., that is expected) but what I really didn't expect was for the memory to stay used when the value objects went out of scope! eh, what can you do? Sure the memory will be freed when garbage collection runs but it is embarrassing to see my service slowly take up more and more memory! Looks like I may have a use, after all, for my object pool code.

                                        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

                                        realJSOPR Offline
                                        realJSOPR Offline
                                        realJSOP
                                        wrote on last edited by
                                        #21

                                        I had a thought - if the objects are too big, they get put on a different heap - one that isn't affected by the garbage collector. Someone else pointed out that you said "local" variable. It might be that the GC won't delete them because it sees them as still in use, so you might want to look into making it global (and maybe static) to the service itself, yet outside the service1 class itself. Maybe also make it disposable.

                                        .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

                                        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