High memory usage

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Willy Denoyette [MVP]

    #16
    Re: High memory usage

    See inline ****
    Willy.

    "Pete" <pvidler@gawab. com> wrote in message news:ECk6b.126$ mi4.84@newsfep1-gui.server.ntli .net...[color=blue]
    > Hi,
    >
    > Philip Carnstam wrote:[color=green]
    > > The whole DotNet idea is ridiculous otherwise... Can I only have 10
    > > home made DotNet applications active at once on a 128 MB Ram machine
    > > before the machine completely runs out of memory?
    > > Sounds mighty strange to me...[/color]
    >
    > There are two things to consider here:
    >
    > 1) In low memory conditions your application will use less memory (try
    > opening many high memory usage applications and see for yourself). You get a
    > similar effect when you application is minimised and restored.
    >[/color]
    **** Note that minimizing app's only results in trimming of the WS, that is pages are returned to the paging file, or are simply
    freed when read-only pages.
    [color=blue]
    > 2) Most of that memory usage is the framework itself.. which *should* be
    > shared between applications running at the same time (someone correct me if
    > I'm wrong with this). If I'm right on this, having many .NET apps open at
    > once should take less memory than having many (similar) non-.net apps open.
    >[/color]
    **** You are (unfortunately) wrong here, FCL (Jitted) code is non-shared, only a part is shared code (the native code DLL's).
    [color=blue]
    > Basically ignore what the task manager is telling you and just write your
    > program.
    >
    > -- Pete
    >
    >[/color]


    Comment

    • Jon Skeet

      #17
      Re: High memory usage

      Willy Denoyette [MVP] <willy.denoyett e@pandora.be> wrote:[color=blue]
      > While it's possible for the CLR to return virtual memory to the
      > OS (Commited or reserved) by calling VirtualFree I never saw he did
      > under memory pressure. The only thing I see is that the OS trims the
      > WS by returning unused (unaccessed) pages to swap file when
      > there is ample memory. As to your remark "The CLR responds to memory
      > requirements of other apps", how do you think the CLR knows about
      > memory requirements of other app's?[/color]

      I don't know the details of how it does it, but it definitely responds
      to memory pressure. A while ago in the framework group someone was
      asking about a program which crashed when there was still garbage
      available to be collected. When two of the programs were run at the
      same time, however, the runtime noticed that there was memory pressure
      and ran the garbage collector more often.

      I know I read about it somewhere, but I can't for the life of me find
      the article now... it could be that I was misinterpreting things, of
      course.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Pete

        #18
        Re: High memory usage

        Hi,

        Willy Denoyette [MVP] wrote:[color=blue]
        > **** Note that minimizing app's only results in trimming of the WS,
        > that is pages are returned to the paging file, or are simply freed
        > when read-only pages.[/color]

        Is there a difference that matters?
        [color=blue]
        > **** You are (unfortunately) wrong here, FCL (Jitted) code is
        > non-shared, only a part is shared code (the native code DLL's).[/color]

        Are you sure? Memory usage for the first .NET app I open appears to be
        around 8 meg (watching freeram xp pro's system memory monitor drop), whereas
        the second app open at the same time uses only 3. It's the same in reverse
        (8 then 3). Under task manager both are shown to use roughly 11MB of memory.
        Surely such a discrepancy cannot be entirely the native DLL's?
        [color=blue][color=green]
        >> Basically ignore what the task manager is telling you and just write
        >> your program.[/color][/color]

        This is still true.

        -- Pete


        Comment

        • Willy Denoyette [MVP]

          #19
          Re: High memory usage

          Pete,
          See inline ****

          Willy.

          "Pete" <pvidler@gawab. com> wrote in message news:fb_6b.1307 7$Ci1.1906885@n ewsfep2-win.server.ntli .net...[color=blue]
          > Hi,
          >
          > Willy Denoyette [MVP] wrote:[color=green]
          > > **** Note that minimizing app's only results in trimming of the WS,
          > > that is pages are returned to the paging file, or are simply freed
          > > when read-only pages.[/color]
          >
          > Is there a difference that matters?[/color]

          *** Yes, note that we are talking about virtual memory, that is the total of real RAM and page file space. When trimming the WS, RW
          pages are moved from memory to the paging file, this does not necessarily reduce the VM size of the process, the net result is a
          performance drop due to disk I/O when paging (in/out).
          [color=blue]
          >[color=green]
          > > **** You are (unfortunately) wrong here, FCL (Jitted) code is
          > > non-shared, only a part is shared code (the native code DLL's).[/color]
          >
          > Are you sure? Memory usage for the first .NET app I open appears to be
          > around 8 meg (watching freeram xp pro's system memory monitor drop), whereas
          > the second app open at the same time uses only 3. It's the same in reverse
          > (8 then 3). Under task manager both are shown to use roughly 11MB of memory.
          > Surely such a discrepancy cannot be entirely the native DLL's?
          >[/color]

          *** If you look at a non NGEN'ed managed application, the shared pages are filled with:

          - The C runtime library (msvcr.dll, msvcrxx.dll)
          - The CLR (mscoree.dll, mscorwks.dll (or mscorsvr.dll) and mscorlib.dll, mscorjit.dll)
          - Native kernel modules (Advapi32.dll, kernel32.dll, user32.dll, gdi32.dll, shell32.dll, etc......)
          - COM (rpcrt4.dll, ole32.dll, oleaut.dll)
          This part accounts for a large amount reserved RO/ RW memory (RO part can be shared amongst all other processes managed/unmanaged).
          The amount depends on the number of pages already loaded by other (unmanaged/managed processes.
          When you start another instance (or any other managed application) only part of the shared code has to be mapped, resulting in a
          smaller memory footprint (virtually !).

          Managed code however, is stored in private pages when Jitted and can as such not be shared. The result is a larger WS for managed
          code compared to non managed code.

          [color=blue][color=green][color=darkred]
          > >> Basically ignore what the task manager is telling you and just write
          > >> your program.[/color][/color]
          >
          > This is still true.
          >
          > -- Pete
          >
          >[/color]


          Comment

          • Angie Ye

            #20
            Re: High memory usage

            I have a much worse problem. The memory usage of my .Net application keeps
            climbing up, eventually the application will crash with an "Out Of Memory"
            error. At that point, the page file size reached 1.45GB. The action of
            minimizing the form will make the Mem Usage drop from hundreds of MB to a
            few MB, but the VM remains the same huge number and keeps increasing, and
            the Mem Usage will climb back even with the form minimized.

            Any idea how to debug a memory leak in C# .Net applications? My aplication
            creates thousands of small objects in local scope, most of them strings. I
            expect the GC would free the memory once the objects are out of scope, but
            it seems our garbage man cannot sweep fast enough.

            Angie

            "Philip Carnstam" <philip.carnsta m@carnstam.net> wrote in message
            news:%23Syq3q9c DHA.652@tk2msft ngp13.phx.gbl.. .[color=blue]
            > How come .Net applications use so much memory? Every application I compile
            > uses at least 10 MB of memory, even the ones consisting of only a form and
            > nothing else. If I minimize them though the memory usage drops to a couple
            > hundred KB. Why?
            >
            > Is there anything I should to to prevent this? I have compiled in release
            > and deactivated all forms of debugging, I think!
            >
            > Thanks,
            > Philip
            >
            >[/color]


            Comment

            • Niall

              #21
              Re: High memory usage

              You can use a memory profiler, like the Scitech .Net Memory Profiler
              (www.scitech.se). There are others too. With such a tool, you can see what's
              still hanging around and what's referencing it. You could also try throwing
              a few GC.Collect calls into your code to see if they actually change
              anything. If they do, it seems that the GC is not running fast enough... if
              they don't, it seems that your objects are not ready to be collected.

              BTW, you can also use the performance monitor to watch the frequency and
              activity of GC behaviour...

              Niall

              "Angie Ye" <aye3002@hotmai l.com> wrote in message
              news:bjjica$m7i $1@sun-news.laserlink. net...[color=blue]
              > I have a much worse problem. The memory usage of my .Net application keeps
              > climbing up, eventually the application will crash with an "Out Of Memory"
              > error. At that point, the page file size reached 1.45GB. The action of
              > minimizing the form will make the Mem Usage drop from hundreds of MB to a
              > few MB, but the VM remains the same huge number and keeps increasing, and
              > the Mem Usage will climb back even with the form minimized.
              >
              > Any idea how to debug a memory leak in C# .Net applications? My aplication
              > creates thousands of small objects in local scope, most of them strings. I
              > expect the GC would free the memory once the objects are out of scope, but
              > it seems our garbage man cannot sweep fast enough.
              >
              > Angie
              >
              > "Philip Carnstam" <philip.carnsta m@carnstam.net> wrote in message
              > news:%23Syq3q9c DHA.652@tk2msft ngp13.phx.gbl.. .[color=green]
              > > How come .Net applications use so much memory? Every application I[/color][/color]
              compile[color=blue][color=green]
              > > uses at least 10 MB of memory, even the ones consisting of only a form[/color][/color]
              and[color=blue][color=green]
              > > nothing else. If I minimize them though the memory usage drops to a[/color][/color]
              couple[color=blue][color=green]
              > > hundred KB. Why?
              > >
              > > Is there anything I should to to prevent this? I have compiled in[/color][/color]
              release[color=blue][color=green]
              > > and deactivated all forms of debugging, I think!
              > >
              > > Thanks,
              > > Philip
              > >
              > >[/color]
              >
              >[/color]


              Comment

              Working...