Object in Context.Items and GC

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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,
 
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
 
Back
Top