[Question] Memory concerns?
See original GitHub issueHi all, thanks for the great library.
I am trying to diagnose what appears to be a memory leak in one of our applications, and I am wanting to make sure I am not misusing or overlooking something with Handlebars. After running our application, which will dynamically load up Handlebars templates, for a long time, generating many templates, I see memory usage continue to grow.
There’s many other pieces to this, so I didn’t even consider Handlebars until I used Visual Studio’s memory profiler and found this:

Where we have (this is a diff) over 200 MB of these ReaderWriterLockSlim objects, and they’re all referenced from HandlebarsDotNet objects.
Our usage of Handlebars is as follows:
string OnEachRequest(...)
{
var handlebars = Handlebars.Create();
//Register custom helpers
...
return handlebars.Compile(someTemplate)(someData);
}
Is there some sort of cleanup I’m forgetting to do?
Thanks! I will continue to dig into this further but figure it doesn’t hurt to ask in case I’m missing something obvious.
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (6 by maintainers)

Top Related StackOverflow Question
@zjklee I think this should be marked as a bug. Running Handlebars 2.0.7, the following eats up all my RAM:
I haven’t dug down exactly what’s happening but each call to
Compileends up throwing more things into that ObservableList that is ultimately referenced by theHandlebarsEnvironmentheld in that static variable, creating a memory leak.I know most people (should) be using a fresh environment, but this is definitely a regression from v1.x
@zjklee Apologies - I just tested this and you are totally correct. I was misremembering the codebase