Memory Usage and Garbage Collection

Discussion in 'ASP .Net' started by Andy, Mar 3, 2004.

  1. Andy

    Andy Guest

    Along with many others I've noticed the large amount of memory that
    can be taken up by the aspnet_wp.exe. I've found that I can better
    control and limit this memory consumption by including a GC.Collect()
    in the Application_EndRequest() event handler in the Global.asax file.

    Whilst this appears to help my memory consumption issues I've also
    read that forced GC.Collect() can be inefficient.

    Assuming that I don't see any adverse effects on performance - which I
    haven't yet, but early days in the testing - does anybody know of any
    reasons why I shouldn't adopt this approach?

    Thanks
    Andy
    Andy, Mar 3, 2004
    #1
    1. Advertising

  2. I think you should be asking if anybody knows of any reasons why you SHOULD
    adopt this approach. The default is to let the Framework manage your memory
    for you, and defaults are defaults for a reason. Unless it's causing a
    problem, I would let the Framework do what is designed to do best.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Andy" <> wrote in message
    news:...
    > Along with many others I've noticed the large amount of memory that
    > can be taken up by the aspnet_wp.exe. I've found that I can better
    > control and limit this memory consumption by including a GC.Collect()
    > in the Application_EndRequest() event handler in the Global.asax file.
    >
    > Whilst this appears to help my memory consumption issues I've also
    > read that forced GC.Collect() can be inefficient.
    >
    > Assuming that I don't see any adverse effects on performance - which I
    > haven't yet, but early days in the testing - does anybody know of any
    > reasons why I shouldn't adopt this approach?
    >
    > Thanks
    > Andy
    Kevin Spencer, Mar 3, 2004
    #2
    1. Advertising

  3. Agreed.

    That said, a deveoper should of course review the ASPX pages and try to
    minimize the memory consumption; converting from strings to stringbuilders
    where necessary, etc.

    --
    Thanks,

    Eric Lawrence
    Program Manager
    Assistance and Worldwide Services

    This posting is provided "AS IS" with no warranties, and confers no rights.


    "Kevin Spencer" <> wrote in message
    news:...
    > I think you should be asking if anybody knows of any reasons why you

    SHOULD
    > adopt this approach. The default is to let the Framework manage your

    memory
    > for you, and defaults are defaults for a reason. Unless it's causing a
    > problem, I would let the Framework do what is designed to do best.
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
    >
    > "Andy" <> wrote in message
    > news:...
    > > Along with many others I've noticed the large amount of memory that
    > > can be taken up by the aspnet_wp.exe. I've found that I can better
    > > control and limit this memory consumption by including a GC.Collect()
    > > in the Application_EndRequest() event handler in the Global.asax file.
    > >
    > > Whilst this appears to help my memory consumption issues I've also
    > > read that forced GC.Collect() can be inefficient.
    > >
    > > Assuming that I don't see any adverse effects on performance - which I
    > > haven't yet, but early days in the testing - does anybody know of any
    > > reasons why I shouldn't adopt this approach?
    > >
    > > Thanks
    > > Andy

    >
    >
    Eric Lawrence [MSFT], Mar 4, 2004
    #3
  4. Thanks a lot for Kevin and Eric's suggestions.

    Hi Andy,

    As Kevin and Eric have mentioned, generally the dotnet clr will
    automatically control the memory management. The "System.GC.Collect" will
    force the clr to execute collection, but System.GC.Collect() is used for
    demonstration purposes, not as a recommended procedure. Explicitly calling
    GC.Collect() changes the GC's autotuning capabilities. Repeatedly calling
    GC.Collect() suspends all threads until the collection completes. This
    could greatly impede performance. And here is the reference on "Forcing
    Garbage Collection" in MSDN:

    #Forcing a Garbage Collection
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconforcingcollection.
    asp?frame=true

    And you may also view the following reference in MSDN for more detailed
    description on Garbage Collection in DOTNET:
    #Programming for Garbage Collection
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconprogrammingessenti
    alsforgarbagecollection.asp?frame=true

    Further more, as you mentioned the performance in ASP.NET, below are some
    tech articles discussing on it:

    #ASP.NET Performance Monitoring, and When to Alert Administrators
    http://msdn.microsoft.com/library/en-us/dnaspp/html/monitor_perf.asp?frame=t
    rue

    #Production Debugging for .NET Framework Applications
    http://msdn.microsoft.com/library/en-us/dnbda/html/DBGch02.asp?frame=true

    Hope these help.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Mar 4, 2004
    #4
  5. Andy

    Andy Guest

    Hi Guys,

    Thanks very much for the advice - I'll revert to letting the GC take
    responsibility. Given that memory consumption on the aspnet_wp seems
    so variable are there any articles or guidelines indicating what
    represents normal operation and what might indicate a design or coding
    problem?

    My project makes extensive use of the 'Cache' for storing sections of
    dynamic pages and I'm a little bit concerned about the scalability of
    this approach, particularly with regards to memory consumption, but
    I'm finding it difficult to get a clear indication of how memory
    requirements of the Cache are varying.

    Thanks,
    Andy

    (Steven Cheng[MSFT]) wrote in message news:<>...
    > Thanks a lot for Kevin and Eric's suggestions.
    >
    > Hi Andy,
    >
    > As Kevin and Eric have mentioned, generally the dotnet clr will
    > automatically control the memory management. The "System.GC.Collect" will
    > force the clr to execute collection, but System.GC.Collect() is used for
    > demonstration purposes, not as a recommended procedure. Explicitly calling
    > GC.Collect() changes the GC's autotuning capabilities. Repeatedly calling
    > GC.Collect() suspends all threads until the collection completes. This
    > could greatly impede performance. And here is the reference on "Forcing
    > Garbage Collection" in MSDN:
    >
    > #Forcing a Garbage Collection
    > http://msdn.microsoft.com/library/en-us/cpguide/html/cpconforcingcollection.
    > asp?frame=true
    >
    > And you may also view the following reference in MSDN for more detailed
    > description on Garbage Collection in DOTNET:
    > #Programming for Garbage Collection
    > http://msdn.microsoft.com/library/en-us/cpguide/html/cpconprogrammingessenti
    > alsforgarbagecollection.asp?frame=true
    >
    > Further more, as you mentioned the performance in ASP.NET, below are some
    > tech articles discussing on it:
    >
    > #ASP.NET Performance Monitoring, and When to Alert Administrators
    > http://msdn.microsoft.com/library/en-us/dnaspp/html/monitor_perf.asp?frame=t
    > rue
    >
    > #Production Debugging for .NET Framework Applications
    > http://msdn.microsoft.com/library/en-us/dnbda/html/DBGch02.asp?frame=true
    >
    > Hope these help.
    >
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    > Get Preview at ASP.NET whidbey
    > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Andy, Mar 4, 2004
    #5
  6. Hi Andy,

    Thanks for your response. I think the following tech articles may help you
    on designing high-performance WEB application and how to properly control
    memory management:

    #Developing High-Performance ASP.NET Applications
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondevelopinghigh-per
    formanceaspnetapplications.asp?frame=true

    #Am I Losing My Memory?
    http://msdn.microsoft.com/library/en-us/dnaskdr/html/askgui09172002.asp?fram
    e=true

    #Performance Counters for ASP.NET
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconPerformanceCounter
    sForASPNET.asp?frame=true

    #ASP.NET Performance Monitoring, and When to Alert Administrators
    http://msdn.microsoft.com/library/en-us/dnaspp/html/monitor_perf.asp?frame=t
    rue

    #Production Debugging for .NET Framework Applications
    http://msdn.microsoft.com/library/en-us/dnbda/html/DBGch02.asp?frame=true

    #ASP.NET Caching Features
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaspcachingfeatures
    ..asp?frame=true


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Mar 4, 2004
    #6
  7. Andy

    Andy Guest

    Hi Steven,

    Thanks for your reply - following your earlier response I worked
    through the articles you directed me to and feel that I am now making
    progress and starting to get a handle on how to memory management
    works - and now I have plenty more reading to do!

    Thanks again,
    Andy

    (Steven Cheng[MSFT]) wrote in message news:<>...
    > Hi Andy,
    >
    > Thanks for your response. I think the following tech articles may help you
    > on designing high-performance WEB application and how to properly control
    > memory management:
    >
    > #Developing High-Performance ASP.NET Applications
    > http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondevelopinghigh-per
    > formanceaspnetapplications.asp?frame=true
    >
    > #Am I Losing My Memory?
    > http://msdn.microsoft.com/library/en-us/dnaskdr/html/askgui09172002.asp?fram
    > e=true
    >
    > #Performance Counters for ASP.NET
    > http://msdn.microsoft.com/library/en-us/cpguide/html/cpconPerformanceCounter
    > sForASPNET.asp?frame=true
    >
    > #ASP.NET Performance Monitoring, and When to Alert Administrators
    > http://msdn.microsoft.com/library/en-us/dnaspp/html/monitor_perf.asp?frame=t
    > rue
    >
    > #Production Debugging for .NET Framework Applications
    > http://msdn.microsoft.com/library/en-us/dnbda/html/DBGch02.asp?frame=true
    >
    > #ASP.NET Caching Features
    > http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaspcachingfeatures
    > .asp?frame=true
    >
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    > Get Preview at ASP.NET whidbey
    > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Andy, Mar 5, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Jones
    Replies:
    0
    Views:
    360
    Richard Jones
    Apr 29, 2004
  2. Øyvind Isaksen
    Replies:
    1
    Views:
    946
    Øyvind Isaksen
    May 18, 2007
  3. David Espada
    Replies:
    1
    Views:
    131
    Masao Mutoh
    Jan 18, 2005
  4. Tridib Bandopadhyay
    Replies:
    25
    Views:
    467
    Tridib Bandopadhyay
    May 20, 2011
  5. Tom Cole
    Replies:
    1
    Views:
    82
    Benjamin
    Mar 10, 2007
Loading...

Share This Page