Saturday, March 24, 2012

why Session.Abandon() does not reduce memory use?

in production environment we started to have a memory consumption problem at
"asp.net wp". after a hard work we have discovered that Session.Abandon()
does not reduce references to objects added to the session and not reduce
memory use.
in Session_End function at Global.asax file we have added the following
lines of code:
== == == == == == == ==
for(int Item = 0; Item < Session.Count; Item++)
Session[Item] = null;
== == == ==
as i suspected it still does not free memory. finally a new line of code was
added "GC.Collect()":
== == == == == == == ==
for(int Item = 0; Item < Session.Count; Item++)
Session[Item] = null;
GC.Collect();
== == == ==
after all of this the memory was free!!!.
Questions:
why Session.Abandon() does not reduce object references?
why Session.Abandon() does not internally force a colecction in order to
free memory?That is because the garbage collector doesn't run constantly. It will run
when it needs to, and reclaim memory then.
You should not be calling GC.Collect yourself.
"Ricardo Q.G." <Ricardo Q.G.@.discussions.microsoft.com> wrote in message
news:7176951C-72F5-462C-94C6-22C7DBB918DC@.microsoft.com...
> in production environment we started to have a memory consumption problem
> at
> "asp.net wp". after a hard work we have discovered that Session.Abandon()
> does not reduce references to objects added to the session and not reduce
> memory use.
> in Session_End function at Global.asax file we have added the following
> lines of code:
> == == == == == == == ==
> for(int Item = 0; Item < Session.Count; Item++)
> Session[Item] = null;
> == == == ==
> as i suspected it still does not free memory. finally a new line of code
> was
> added "GC.Collect()":
> == == == == == == == ==
> for(int Item = 0; Item < Session.Count; Item++)
> Session[Item] = null;
> GC.Collect();
> == == == ==
> after all of this the memory was free!!!.
>
> Questions:
> why Session.Abandon() does not reduce object references?
> why Session.Abandon() does not internally force a colecction in order to
> free memory?
>
As a side note, depending on the exact problem you saw you may want to try
to call dispose/close if you have stored such objects in Session...
--
Patrice
"Marina" <someone@.nospam.com> a crit dans le message de
news:%23ELI6yElFHA.2156@.TK2MSFTNGP14.phx.gbl...
> That is because the garbage collector doesn't run constantly. It will run
> when it needs to, and reclaim memory then.
> You should not be calling GC.Collect yourself.
> "Ricardo Q.G." <Ricardo Q.G.@.discussions.microsoft.com> wrote in message
> news:7176951C-72F5-462C-94C6-22C7DBB918DC@.microsoft.com...
problem
Session.Abandon()
reduce
>

0 comments:

Post a Comment