By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

Object in Context.Items and GC

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
http://www.OdeToCode.com/blogs/scott

On Mon, 17 May 2004 09:36:10 -0700, John Linn
<an*******@discussions.microsoft.com> wrote:
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


Nov 18 '05 #2

P: n/a
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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.