Cleanup helper domain not unloaded after dispose (Or: how to implement a recycle strategy)
Hello,
I'm trying to implement a recycle policy that after a certain number of recompilations will reload the AppDomain and cleanup memory and temp files. The only way I have found so far is to simply dispose IsolatedRazorEngineService and create a new one. This will unload AppDomain used for rendering and clean up some memory and it seemed fine at beginning.
Unfortunately, the appdomain created in CrossAppDomainCleanUp (called "CleanupHelperDomain_
Example:
using (var service = IsolatedRazorEngineService.Create())
{
service.AddTemplate("TestTemplate",
"Hello @Model.Name " + new String(Enumerable.Repeat('A', 100000).ToArray()));
service.Compile("TestTemplate", typeof(TemplateModel));
}
// Now there is ONE CrossAppDomainCleanUp app domain
using (var service = IsolatedRazorEngineService.Create())
{
service.AddTemplate("TestTemplate",
"Hello @Model.Name " + new String(Enumerable.Repeat('A', 100000).ToArray()));
service.Compile("TestTemplate", typeof(TemplateModel));
}
// Now there are TWO CrossAppDomainCleanUp app domains
Is this a bug or am I doing something wrong? What is the best way to implement a recycle strategy?
Any help appreciated.
If I uncomment this line, the problem goes away:
https://github.com/Antaris/RazorEngine/blob/master/src/source/RazorEngine.Core/Compilation/CrossAppDomainCleanUp.cs#L368
Is there any reason that it is commented out?
Interesting IIRC I couldn't make the line work. Can you send a pr with the line uncommented?
It could also be that I commented because of reported issues (but then git blame should show it, which it isn't)
It was already commented out when the entire class was introduced: https://github.com/Antaris/RazorEngine/commit/a76daaad4e1d18f6a19c60dd9d248aa09733483d
I'll fix a PR with a test shortly
See #493
#463 is a duplicate of this.
Hi there, is there any plan to get this issue fixed? I am experiencing the same problem. Are there any drawbacks to the proposed solution?
Any updates on this?
I'm not developer of RazorEngine, but I want to share our experience. We are migrated to Microsoft.NET.Sdk.Razor libraries. It's much more robust and maintained that "old" non-Core razor, and because it could be build compile-time it could be embedded into "old" ASP.NET MVC applications and ASP.NET Core application and basically everywhere. However, we don't need run-time compilation.