Object in Context.Items and GC

G

Guest

If I add an object to HttpContext.Current.Items, does that mean it will last the duration of the page request? If not, what controls when that object will be cleaned up

-J
 
S

Scott Allen

Hi John:

The object will be around for the entire duration of the page request.

Generally you can let the runtime worry about cleaning up the object
with garbage collection, but of course there are always exceptions.

If I have an IDisposable object in the the items collection, I would
put code into the Application_EndRequest method of global.asax to call
Dispose, or Close, or whatever method the object exposes to do cleanup
of important resources.

HTH,
 
G

Guest

Scott

Thanks for the answer. I wanted to put an object in context for all my user controls to access, but I only need a couple of the properties from that object. I worry that if it lasts the entire page, it would lead to excessive Gen1 collections. The current app has too much GC going on

Instead of adding them to Context, I will just create a class for my users controls to inherit that would set these properties from my objects and then I'll mark the object for cleanup

-

----- Scott Allen wrote: ----

Hi John

The object will be around for the entire duration of the page request

Generally you can let the runtime worry about cleaning up the objec
with garbage collection, but of course there are always exceptions.

If I have an IDisposable object in the the items collection, I woul
put code into the Application_EndRequest method of global.asax to cal
Dispose, or Close, or whatever method the object exposes to do cleanu
of important resources.

HTH
-
Scot
http://www.OdeToCode.com/blogs/scot
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top