Skip to content

Commit 76c7986

Browse files
committed
Change for #271. Assumption about memory leak because of circular reference was incorrect (verified by testing). Moved functionality to set the ControllerContext property of the controller to the new ControllerContext instance within the MvcContextFactory.
1 parent a5713a7 commit 76c7986

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/MvcSiteMapProvider/MvcSiteMapProvider/Security/AuthorizeAttributeAclModule.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,10 @@ protected virtual bool VerifyController(ISiteMapNode node, RouteData routes, Typ
112112
var controllerContext = this.CreateControllerContext(node, routes, controllerType, controllerFactory, out factoryBuiltController);
113113
try
114114
{
115-
// Fixes #271 - set controller's ControllerContext property for MVC
116-
controllerContext.Controller.ControllerContext = controllerContext;
117-
118115
return this.VerifyControllerAttributes(node, controllerType, controllerContext);
119116
}
120117
finally
121118
{
122-
// Release the circular reference between Controller-ControllerContext, so it can be GC'd
123-
controllerContext.Controller.ControllerContext = null;
124-
125119
// Release controller
126120
if (factoryBuiltController)
127121
controllerFactory.ReleaseController(controllerContext.Controller);

src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Mvc/MvcContextFactory.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ public virtual ControllerContext CreateControllerContext(RequestContext requestC
5252
if (controller == null)
5353
throw new ArgumentNullException("controller");
5454

55-
return new ControllerContext(requestContext, controller);
55+
var result = new ControllerContext(requestContext, controller);
56+
57+
// Fixes #271 - set controller's ControllerContext property for MVC
58+
result.Controller.ControllerContext = result;
59+
60+
return result;
5661
}
5762

5863
public virtual IRequestCache GetRequestCache()

0 commit comments

Comments
 (0)