473,783 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memory Usage and Garbage Collection

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_End Request() 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
Nov 18 '05 #1
6 1929
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" <an****@adownin g.freeserve.co. uk> wrote in message
news:fc******** *************** ***@posting.goo gle.com...
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_End Request() 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

Nov 18 '05 #2
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" <ke***@takempis .com> wrote in message
news:uT******** ******@tk2msftn gp13.phx.gbl...
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" <an****@adownin g.freeserve.co. uk> wrote in message
news:fc******** *************** ***@posting.goo gle.com...
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_End Request() 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


Nov 18 '05 #3
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.Coll ect" will
force the clr to execute collection, but System.GC.Colle ct() 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...cingcollection.
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...rammingessenti
alsforgarbageco llection.asp?fr ame=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...rf.asp?frame=t
rue

#Production Debugging for .NET Framework Applications
http://msdn.microsoft.com/library/en...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

Nov 18 '05 #4
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

v-******@online.m icrosoft.com (Steven Cheng[MSFT]) wrote in message news:<uu******* *******@cpmsftn gxa06.phx.gbl>. ..
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.Coll ect" will
force the clr to execute collection, but System.GC.Colle ct() 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...cingcollection.
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...rammingessenti
alsforgarbageco llection.asp?fr ame=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...rf.asp?frame=t
rue

#Production Debugging for .NET Framework Applications
http://msdn.microsoft.com/library/en...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

Nov 18 '05 #5
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...lopinghigh-per
formanceaspneta pplications.asp ?frame=true

#Am I Losing My Memory?
http://msdn.microsoft.com/library/en...72002.asp?fram
e=true

#Performance Counters for ASP.NET
http://msdn.microsoft.com/library/en...ormanceCounter
sForASPNET.asp? frame=true

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

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

#ASP.NET Caching Features
http://msdn.microsoft.com/library/en...achingfeatures
..asp?frame=tru e
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

Nov 18 '05 #6
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

v-******@online.m icrosoft.com (Steven Cheng[MSFT]) wrote in message news:<Lk******* *******@cpmsftn gxa06.phx.gbl>. ..
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...lopinghigh-per
formanceaspneta pplications.asp ?frame=true

#Am I Losing My Memory?
http://msdn.microsoft.com/library/en...72002.asp?fram
e=true

#Performance Counters for ASP.NET
http://msdn.microsoft.com/library/en...ormanceCounter
sForASPNET.asp? frame=true

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

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

#ASP.NET Caching Features
http://msdn.microsoft.com/library/en...achingfeatures
.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

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4149
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database periodically. What happens, is that the app reads the contents of a text file line by line into an ArrayList. Each element of the ArrayList is a string representing a record from the file. The ArrayList is then processed, and the arraylist goes out of...
20
4244
by: Philip Carnstam | last post by:
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
7
1630
by: Casey Leamon | last post by:
I've been noticing that all of my .NET apps seem to progressivly use more and more memory. Even after several reworks of the code I can only manage to slow the growth. Is there some Garbage Collection caveat that's holding old data into higher generations accidentlly? Has anyone else noticed this?
25
2388
by: Zeng | last post by:
I finally narrowed down my code to this situation, quite a few (not all) of my CMyClass objects got hold up after each run of this function via the simple webpage that shows NumberEd editbox. My memory profile shows that those instances survive 3 rounds of GC collections - it's not what I expected. In my real code, CMyClass occupies big amount of memory and they all share one stance of another class that I don't have enough memory hold...
7
7173
by: Clement | last post by:
hi, i have an asp.net site and is using SQL Server 2k. i realize the aspnet_wp.exe memory usage keep growing and i will receive an error for the pages that call the sql connection. others page with no sql connection is fined. At the time when i encounter the error, i check the memory usage for aspnet_wp.exe = 60000kb sqlmangr.exe = 40000kb
8
8554
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of each object within my JS app to help locate my problem? Thanks
3
5327
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". Anybody know anything about this? Does *Javascript* leak memeory, or does the *browser* leak memory?
2
1876
by: roger.dunham | last post by:
I am trying to identify whether a .NET 1.1 application that I have written has a memory leak. I thought I understood how .NET memory management worked, but it appears that there is more to it than I realised. I have created a simple app that creates a byte array which is stored as a member of the application's main form. The important code is shown below.
9
4179
by: deerchao | last post by:
I'm developing a WinForms application. It slowly eats up memory, one client reported that it took 200MB or more, and finnaly crashed. I myself noticed it's common to use up 30MB memory, but if I minimize it (all the Forms will Hide, only a NotifyIcon is shown at the System Notification Area), the memory usage comes down to 8MB immediately. After that, even if I show the Forms again, it uses only 8MB memory. Do I have another way to...
11
4237
by: dhtml | last post by:
(originally mis-posted on m.p.s.jscript...) I've just closed all windows in Firefox and its using 244MB of memory. I have no idea why. I had GMail open, a page from unicode, the CLJ FAQ. I've noticed that createElement leaks. It's obvious with form controls because the form keeps the control name as a property. Example:
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.