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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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 said:
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. said:
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?
 
Even further to the side, you really shouldn't be putting big things
into the Session. It's intended for UserIDs and the occasional little
string. If you have something living there that's big enough to notice
in the aspnet_wp process, you should probably consider refactoring your
application.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 
Back
Top