2

Is it possible to recover memory lost from w3wp.exe? I thought a session.abandon() should clear up the resources like that? The thing is I have a web application, certain pages make w3wp.exe grow significantly. Like from 40 MB to 400 MB. Now I am going to optimize my code defiantly to reduce this, however for what ever amount the w3wp.exe grows, is there no way to recover the lost memory even when the user has logged out and closed the browser?

I know this worker process will recycle after 30 minutes (default) of idle use, but what if there is no idle use-age for a long time and the worker process still has that portion of memory, it just keeps on growing? Any thoughts people?

xeshu
  • 788
  • 2
  • 11
  • 24
  • Are you seeing the memory footprint of the service growing when you start a new session after closing out an old one? – Achilles Jul 29 '10 at 13:38
  • Yes. My w3wp.exe goes to 400MB on a specific page, even after user logging out (session.abandon()), the next user comes in, visits that page and poof the w3wp.exe goes to 700Mb. – xeshu Jul 29 '10 at 14:09
  • It seems you're putting an awful lot of data in the session. Instead, use a file or database to store large amounts of data. – Mauricio Scheffer Jul 29 '10 at 14:12
  • Well basically the page that bloats up the w3wp.exe is the page that calls up a large number of 2mb word files from database table column (binary) and displays on a grid. I now know this is not the way forward, so the page actually shows 400 MB worth of data. Some lame programmer at our company told me to save documents on the database. The result of that is this. – xeshu Jul 29 '10 at 14:29
  • If you happen to be using SQL Server 2008 you can use the new filestream type to avoid having to load the whole thing in memory. – Mauricio Scheffer Jul 29 '10 at 19:36

2 Answers2

0

The garbage collector will take care of whatever memory needs to be freed, provided that you dispose things correctly, etc. The GC doesn't immediately kick in every time you call Session.Abandon(), as that would be a major performance hit.

That said, every application has a "normal" memory usage, i.e. a stable memory usage (again, provided you don't have leaks), and this figure is different for every application. 400MB can be a lot or it can be nothing, depending on what your app does. I have apps that hover around 400MB and others around 1.5GB and that's OK as long as memory usage stabilizes somewhere. If you see unbounded memory usage then you most likely have a leak somewhere in your app.

Storing large amounts of data in the in-proc session can also quickly rack up the memory usage. Instead, use a file or a database to store this data.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • Well basically, I am not at all disposing any objects. I thought the 'using' part of c# should take care of the disposing business? And yes my production deployment does not do a session.abandon(). I just realised that and will be putting that on the code but that may not be of much use since 99.9% of the users dont really bother pressing the logout button, they just simply close the browser. – xeshu Jul 29 '10 at 14:12
0

unless you are leaking the memory, the memory manager will re-use this memory so you should not see the process memory keep growing.

Mike
  • 3,462
  • 22
  • 25