When it the method(ReleaseView) gets called?
It is called by the ViewResultBase.ExecuteResult
method:
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (string.IsNullOrEmpty(this.ViewName))
{
this.ViewName = context.RouteData.GetRequiredString("action");
}
ViewEngineResult result = null;
if (this.View == null)
{
result = this.FindView(context);
this.View = result.View;
}
TextWriter output = context.HttpContext.Response.Output;
ViewContext viewContext = new ViewContext(context, this.View, this.ViewData, this.TempData, output);
this.View.Render(viewContext, output);
if (result != null)
{
result.ViewEngine.ReleaseView(context, this.View);
}
}
Notice how once the view is rendered to the output stream, the ReleaseView method is called. So basically every time a controller action returns a View or a PartialView, when this ActionResult completes executing it will call the ReleaseView method on the underlying view engine.
And where are the other places it can be used ?
For example if you are writing custom ActionResults.
So, can i make use of this method in my controller action ?
No, the controller action has finished executing much before the view engine starts executing.