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

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?
 
M

Marina

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.
 
P

Patrice

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?
 
J

jasonkester

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top