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. Memory usage problem

Memory usage problem

Scheduled Pinned Locked Moved C#
questionperformancehelp
7 Posts 6 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
    Lost User
    wrote on last edited by
    #1

    I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...

    H D F D 4 Replies Last reply
    0
    • L Lost User

      I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...

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

      As far as i know, when you do something like GC.Collect(); your not telling the garbage collector to collect the object, your merely flagging that object for garbage collection. So when the garbage collector comes along(at a later point in time) it will collect the object you flagged. If you post your code(specifically the loop) we might be able to get the memory usage down a bit...

      Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 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

      D 1 Reply Last reply
      0
      • L Lost User

        I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        I believe it's not actual memory usage that you're seeing in Task Manager - just memory that Windows has pre-allocated to your app. Any memory allocated but unused will be reclaimed if needed elsewhere or when minimized which is why you're seeing those figures.

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Expect everything to be hard and then enjoy the things that come easy. (code-frog)

        1 Reply Last reply
        0
        • L Lost User

          I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...

          F Offline
          F Offline
          Frank Horn
          wrote on last edited by
          #4

          You may want to try GC.WaitForPendingFinalizers() as well. It's a perfomance killer and not recommended in most situations, but it could be interesting to see if it changes the memory usage you see in task manager.

          1 Reply Last reply
          0
          • H Harvey Saayman

            As far as i know, when you do something like GC.Collect(); your not telling the garbage collector to collect the object, your merely flagging that object for garbage collection. So when the garbage collector comes along(at a later point in time) it will collect the object you flagged. If you post your code(specifically the loop) we might be able to get the memory usage down a bit...

            Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 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

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

            You're not flagging anything with GC.Collect. You're just telling the GC you'd LIKE a garbage collection to occur at this time. But, it's up to the GC if it wants to do it or not. When a collection runs, your app stops while the GC walks the heap looking for objects that need to be collected.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            1 Reply Last reply
            0
            • L Lost User

              I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...

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

              Learn how memory work under the .NET CLR. What you're seeing in Task Manager, which is a lousy place to look for memory usage by the way, you're seeing what memory the .NET CLR has reserved for your app. Your app may not be using all of this memory, but it's sitting in the .NET CLR Managed memory pool, waiting for your app to allocate some memory for objects or whatnot. When you minimize your app, the .NET CLR looks to see if there is any memory in the Managed Pool that isn't being used by your app and, from what it can tell, isn'tgoing to be used anytime soon. If so, this memory is taken out of the Managed Pool and returned to Windows. Basically, you're worried about nothing. The .NET CLR is very good at managing it's memory and cooperating with Windows. If Windows needs memory back from the .NET CLR, the CLR is more than happy to scan it's pools to see what it can return to Windows. ...entirely automatically. You don't need to do anything.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              D 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Learn how memory work under the .NET CLR. What you're seeing in Task Manager, which is a lousy place to look for memory usage by the way, you're seeing what memory the .NET CLR has reserved for your app. Your app may not be using all of this memory, but it's sitting in the .NET CLR Managed memory pool, waiting for your app to allocate some memory for objects or whatnot. When you minimize your app, the .NET CLR looks to see if there is any memory in the Managed Pool that isn't being used by your app and, from what it can tell, isn'tgoing to be used anytime soon. If so, this memory is taken out of the Managed Pool and returned to Windows. Basically, you're worried about nothing. The .NET CLR is very good at managing it's memory and cooperating with Windows. If Windows needs memory back from the .NET CLR, the CLR is more than happy to scan it's pools to see what it can return to Windows. ...entirely automatically. You don't need to do anything.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                D Offline
                D Offline
                Dan Neely
                wrote on last edited by
                #7

                Dave Kreskowiak wrote:

                What you're seeing in Task Manager, which is a lousy place to look for memory usage by the way, you're seeing what memory the .NET CLR has reserved for your app. Your app may not be using all of this memory, but it's sitting in the .NET CLR Managed memory pool, waiting for your app to allocate some memory for objects or whatnot.

                Expanding upon this; The CLR does it because asking for more memory from the kernel is an expensive operation, it's much faster to ask for a large block up front than to keep asking for little bits as needed. Also when system memory starts getting low, windows will go around asking applications if they can return extra unused memory. When this happens the same thing will occur as when you minimize the application.

                Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                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