Bugzilla – Bug 381
Memory leak in asp.net with sessions enabled
Last modified: 2012-10-02 06:38:34 EDT
Created attachment 179 [details]
A simple web application will consume ever increasing amounts of memory when
run with sessions enabled. This appears to be related to CacheItems being
created rapidly without being garbage collected. Behaviour seen with both boehm
and sgen collection.
See also http://go-mono.com/forums/#nabble-td3264509
Running on mono 2.10.2, observed with both mvc2 (test case attached) and mvc3.
To reproduce: Run the test case, point a couple of browser tabs at it and
monitor memory usage over time. This will take a while to become evident (since
CacheItems are small).
I suspect this is a cause of the mysterious problems that mono sites under high
load experience, referred to here
Any chance you could test this on 2.10.4?
I see exactly the same behaviour on 2.10.4
Thanks Justin, looks like some of our devs are now able to reproduce. Hopefully
they can find & fix the issue :-)
Gonzalo, was this patch backported to 2-10?
This was on 2011-09-29/2011-09-30
Author: Gonzalo Paniagua Javier <firstname.lastname@example.org>
Date: Fri Sep 30 01:20:29 2011 -0400
Plug an unmanaged memory leak
If Flush() was called with final_flush set to true, we were leaking the
unmanaged memory in the output stream (if allocated).
It was "only" an AS leak.
Thanks to Kumpera for the help debugging this.
...but that leak has nothing to do with sessions or caching
We're still seeing this issue with mono 2.10.8 unfortunately.
My test case uses the MVC3 and if I set:
<sessionState mode="Off" />
in the web.config it does not leak at all (running through XSP).
I discovered something new today when playing with the SessionState attribute,
since we may want to selectively enable/disable session state in our
In my test case I set:
<sessionState mode="InProc" cookieless="false" timeout="20" />
and then used:
in the controller.
This should have the same result as setting the session state mode to off in
the web.config, but only applied to specific controllers. However, I still saw
leaking of the same magnitude as before!
Hopefully this information may be useful.
Update to my previous comment:
Having checked a few things I found that I could still write values into the
session in my controller, whereas it should be throwing an exception. It seems
that the controller SessionState is not being applied in mono (is this another
The leak is still happening though and we have been working on the next version
of our application in the hope that this problem will be addressed before we
have to ship.
Any status on this issue? I also see significant leaks in my application,
requiring several restarts per day to keep things running smoothly. :(
We gave up hoping that this would be fixed and instead looked for an
application it made sense to switch to a REST service based system running in a
console (mono + ubuntu).
We now use the awesome ServiceStack (http://www.servicestack.net/) running as a
I wrote a post about our problems and solutions at