RazorEngine un-cache compiled templates

后端 未结 3 1299
萌比男神i
萌比男神i 2021-02-07 15:02

Currently, I am using RazorEngine v2.1 as part of a background process that sends templated emails (thousands of them). To speed things up, the templates are compiled with their

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 15:27

    Answering this because it still seems to be relevant for some people. (https://github.com/Antaris/RazorEngine/issues/232#issuecomment-128802285)

    For this particular process, which might run for months at a time without a restart, this could constitute a serious memory leak if all the previous versions of templates are still hanging around.

    When you change and recompile templates you have a memory leak, because you cannot unload loaded assemblies (which RazorEngine compiles and loads for you in the background).

    The only way to really free the memory is to reload the AppDomain or restart the process.

    The other answers seem to talk about newer versions which prevent memory leaks in the default configuration (to make you aware of the problem) and require some custom configuration to be able to recompile a key with another template code. Note that all the other answers will actually increase memory consumption!

    matthid, a RazorEngine contributor

提交回复
热议问题