From 9bc3fdd5559dccdebf68d6a155b9e48e1be1875f Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 31 Jul 2013 17:34:42 +1000 Subject: [PATCH] Makes UmbracoContext disposable and fixes the module's DisposeHttpContextItems to actual perform the disposal of each item. --- src/Umbraco.Web/UmbracoContext.cs | 16 ++++++-- src/Umbraco.Web/UmbracoModule.cs | 62 ++++++++++++++++--------------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 471e7403ad..abec9e4076 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -24,7 +24,7 @@ namespace Umbraco.Web /// /// Class that encapsulates Umbraco information of a specific HTTP request /// - public class UmbracoContext + public class UmbracoContext : DisposableObject { private const string HttpContextItemName = "Umbraco.Web.UmbracoContext"; private static readonly object Locker = new object(); @@ -361,7 +361,17 @@ namespace Umbraco.Web return null; } } - - + + protected override void DisposeResources() + { + Security.DisposeIfDisposable(); + Security = null; + _previewContent = null; + _umbracoContext = null; + //ensure not to dispose this! + Application = null; + ContentCache = null; + MediaCache = null; + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index c93b99d180..604e61e55f 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.IO; using System.Linq; using System.Web; @@ -166,23 +167,6 @@ namespace Umbraco.Web return end; } - /// - /// Checks if the xml cache file needs to be updated/persisted - /// - /// - /// - /// TODO: This needs an overhaul, see the error report created here: - /// https://docs.google.com/document/d/1neGE3q3grB4lVJfgID1keWY2v9JYqf-pw75sxUUJiyo/edit - /// - void PersistXmlCache(HttpContextBase httpContext) - { - if (content.Instance.IsXmlQueuedForPersistenceToFile) - { - content.Instance.RemoveXmlFilePersistenceQueue(); - content.Instance.PersistXmlToFile(); - } - } - #endregion #region Route helper methods @@ -350,7 +334,7 @@ namespace Umbraco.Web /// /// /// - private void RewriteToUmbracoHandler(HttpContextBase context, PublishedContentRequest pcr) + private static void RewriteToUmbracoHandler(HttpContextBase context, PublishedContentRequest pcr) { // NOTE: we do not want to use TransferRequest even though many docs say it is better with IIS7, turns out this is // not what we need. The purpose of TransferRequest is to ensure that .net processes all of the rules for the newly @@ -402,6 +386,36 @@ namespace Umbraco.Web } } + /// + /// Checks if the xml cache file needs to be updated/persisted + /// + /// + /// + /// TODO: This needs an overhaul, see the error report created here: + /// https://docs.google.com/document/d/1neGE3q3grB4lVJfgID1keWY2v9JYqf-pw75sxUUJiyo/edit + /// + static void PersistXmlCache(HttpContextBase httpContext) + { + if (content.Instance.IsXmlQueuedForPersistenceToFile) + { + content.Instance.RemoveXmlFilePersistenceQueue(); + content.Instance.PersistXmlToFile(); + } + } + + /// + /// Any object that is in the HttpContext.Items collection that is IDisposable will get disposed on the end of the request + /// + /// + private static void DisposeHttpContextItems(HttpContext http) + { + foreach (DictionaryEntry i in http.Items) + { + i.Value.DisposeIfDisposable(); + i.Key.DisposeIfDisposable(); + } + } + #region IHttpModule /// @@ -469,18 +483,6 @@ namespace Umbraco.Web #endregion - /// - /// Any object that is in the HttpContext.Items collection that is IDisposable will get disposed on the end of the request - /// - /// - private static void DisposeHttpContextItems(HttpContext http) - { - foreach(var i in http.Items) - { - i.DisposeIfDisposable(); - } - } - #region Events internal static event EventHandler RouteAttempt; private void OnRouteAttempt(RoutableAttemptEventArgs args)