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. General Programming
  3. C#
  4. Problem in memory usage in .net

Problem in memory usage in .net

Scheduled Pinned Locked Moved C#
csharphelpperformancequestion
7 Posts 5 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.
  • K Offline
    K Offline
    Kim0618
    wrote on last edited by
    #1

    Hi, I have written a complex program in c#.net. After the program is running for a long time by user interactions, its memory usage will increase to the limit of the system, then error will occur. How can the program alert the user that the memory usage is nearly close to its limit before it goes into error ? I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively. Thanks

    H D L 3 Replies Last reply
    0
    • K Kim0618

      Hi, I have written a complex program in c#.net. After the program is running for a long time by user interactions, its memory usage will increase to the limit of the system, then error will occur. How can the program alert the user that the memory usage is nearly close to its limit before it goes into error ? I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively. Thanks

      H Offline
      H Offline
      Harvey Saayman
      wrote on last edited by
      #2

      Kim0618 wrote:

      After the program is running for a long time by user interactions, its memory usage will increase to the limit

      This is not good, I suspect that somewhere maybe stuff gets put into a collection of some kind and never removed. I suggest getting a memory profiler to point out these flaws for you. Hope you figure it out

      Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

      R 1 Reply Last reply
      0
      • H Harvey Saayman

        Kim0618 wrote:

        After the program is running for a long time by user interactions, its memory usage will increase to the limit

        This is not good, I suspect that somewhere maybe stuff gets put into a collection of some kind and never removed. I suggest getting a memory profiler to point out these flaws for you. Hope you figure it out

        Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

        R Offline
        R Offline
        Rob Philpott
        wrote on last edited by
        #3

        Agreed. Don't understand why anyone would vote that a bad answer. Something which just keeps growing over time needs reviewing.

        Regards, Rob Philpott.

        1 Reply Last reply
        0
        • K Kim0618

          Hi, I have written a complex program in c#.net. After the program is running for a long time by user interactions, its memory usage will increase to the limit of the system, then error will occur. How can the program alert the user that the memory usage is nearly close to its limit before it goes into error ? I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively. Thanks

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You're probably not disposing of something properly, or you're not maintaining a collection of object properly, or any number of other causes. You need to look at your app run with a profiler to find out what's going on. This is something that you should have been testing for before it got deployed to production.

          Kim0618 wrote:

          I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively.

          This has nothing to do with the GC's inability to do it's job. It can still do it's job very effectively, even on the most complex of applications.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          1 Reply Last reply
          0
          • K Kim0618

            Hi, I have written a complex program in c#.net. After the program is running for a long time by user interactions, its memory usage will increase to the limit of the system, then error will occur. How can the program alert the user that the memory usage is nearly close to its limit before it goes into error ? I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively. Thanks

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

            There are many ways to run out of memory. The most obvious one is keeping things around that you no longer need but for some reason still hold on to. .NET sometimes has a problem with the "large object heap" (LOH) which never gets compacted, and may run out of space. A popular culprit is a collection growing larger and larger. As soon as it hold 20,000+ objects, the reference array is a large object (as it exceeds 80KB); any time it needs more capacity, it gets reallocated with twice its size. The space occupied by the old array is freed, but will not be reused by that same array as it keeps growing. Of course the objects themselves in the collection also take memory; that may or may not come from the LOH, depending on their size. If, I don't know you do, but if you are building a cache of some sort, you should keep its size in check, and probably use WeakReference techniques. :)

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


            Happy New Year to all.
            We hope 2010 soon brings us automatic PRE tags!
            Until then, please insert them manually.


            K 1 Reply Last reply
            0
            • L Luc Pattyn

              There are many ways to run out of memory. The most obvious one is keeping things around that you no longer need but for some reason still hold on to. .NET sometimes has a problem with the "large object heap" (LOH) which never gets compacted, and may run out of space. A popular culprit is a collection growing larger and larger. As soon as it hold 20,000+ objects, the reference array is a large object (as it exceeds 80KB); any time it needs more capacity, it gets reallocated with twice its size. The space occupied by the old array is freed, but will not be reused by that same array as it keeps growing. Of course the objects themselves in the collection also take memory; that may or may not come from the LOH, depending on their size. If, I don't know you do, but if you are building a cache of some sort, you should keep its size in check, and probably use WeakReference techniques. :)

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


              Happy New Year to all.
              We hope 2010 soon brings us automatic PRE tags!
              Until then, please insert them manually.


              K Offline
              K Offline
              Kim0618
              wrote on last edited by
              #6

              Thanks for your answer ! But what is the weak reference technique that you have mentioned ?

              L 1 Reply Last reply
              0
              • K Kim0618

                Thanks for your answer ! But what is the weak reference technique that you have mentioned ?

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

                You're welcome. You might want and read up on WeakReference class. :)

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


                Happy New Year to all.
                We hope 2010 soon brings us automatic PRE tags!
                Until then, please insert them manually.


                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