 Rank: Fanatic
Joined: 9/17/2007 Posts: 265 Location: London, UK.
|
Hey, The component I'm working on has an event handler: Code:public void Init(HttpApplication application) { application.BeginRequest += (new EventHandler(this.Application_BeginRequest)); } I'm putting properties into a static library (using Singleton pattern) and also caching various bits and pieces. When I monitor the memory usage in task manager, I see that every time I refresh the browser, the (XP) IIS memory in use goes up 3-500KB. Not very scientific, I know but... Read this article, " The Event Handlers That Made The Memory Baloon" (sic). Now I'm suddenly suspicious. Maybe the core team know better but with stuff that might hang around longer than the lifetime of the page, is there a step that can be taken to nullify the memory leak? 500KB every page refresh = certain application death... I'm no expert - trust me! - so I could be barking up the wrong tree but if there is validity to this scenario, I hope someone more versed in .Net than I has some advice to give. Richard
2 * 3 * 3 * 37 : The prime factorisation of The Beast.
|
 Rank: Devotee
Joined: 3/19/2008 Posts: 52 Location: London
|
I'm not so sure about that article because it tackles a topic that is affected by such a broad number of issues and it hasn't really offered a eureka-type answer for me.
First thing I'd ask is - never mind how fast the memory grows, have you kept refreshing till you run out of memory? Does that ever happen?
The reason that I ask is that the Garbage collector is generational, and things that live longer than one page lifecycle would have a high chance of being promoted out of generation 1 and into generation 2 or even 3. Now the garbage collector will probably do more collections in generation 1 and will only scavenge generations 2 & 3 when you really start to run out of memory. So in essence, because you're caching stuff it lives longer and I'd expect the memory usage to be high, even when you release your references.
The main dangers in your scenario would be:
1. umanaged resources - if they aren't released, they wont be collected
2. strings - if you're doing a lot of string manipulation, try use string.concat and system.text.stringbuilder otherwise every you have lots of immutable strings that you throw away on every event
I might be preaching to the converted here though - just guessing with my suggestions becuase I don't know the specifics of your singleton class and what it does when the event fires...
Neil
Disclaimer: Projectstream Ltd (UK) and its directors make no representations as to accuracy, completeness, currentness, suitability, or validity of any information provided in the Umbraco Forum and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis and is for informational purposes only.
That being said, if you think I'm mad then please tell me. Alternatively if you think I've been really helpful thats wonderful.
|
 Rank: Fanatic
Joined: 9/17/2007 Posts: 265 Location: London, UK.
|
Good call. The memory does fluctuate quite alarmingly at times but eventually, some gets returned so I imagine the garbage collector fired up.
We don't use unmanaged resources.
I need to get a calculator out to make sure we have enough memory to hold the extra cached stuff for the number of visitors we get.
I'm still interested in that event handler article if anyone else has input.
Richard
2 * 3 * 3 * 37 : The prime factorisation of The Beast.
|