question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Memory concerns?

See original GitHub issue

Hi 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:

image

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:closed
  • Created 2 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Zulu-Inuoecommented, Jun 10, 2021

@zjklee I think this should be marked as a bug. Running Handlebars 2.0.7, the following eats up all my RAM:

            while(true)
            {
                Handlebars.Compile("Hello, world!");
            }

I haven’t dug down exactly what’s happening but each call to Compile ends up throwing more things into that ObservableList that is ultimately referenced by the HandlebarsEnvironment held 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

0reactions
Zulu-Inuoecommented, Jul 27, 2021

@zjklee Apologies - I just tested this and you are totally correct. I was misremembering the codebase

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory, Forgetfulness, and Aging: What's Normal and What's ...
What's normal forgetfulness and what's not? · Asking the same questions over and over again · Getting lost in places a person knows...
Read more >
Memory Loss: Causes, Symptoms & Treatment
Memory loss is when you have consistent issues remembering things you could previously recall. It can be either temporary or permanent.
Read more >
10 Steps to Approach Memory Concerns in Others
10 Steps to Approach Memory Concerns in Others ; 1. What changes in memory, thinking or behavior do you see? ; 2. What...
Read more >
Forgetfulness — 7 types of normal memory problems
Seven normal memory problems · 1. Transience. This is the tendency to forget facts or events over time. · 2. Absentmindedness. This type...
Read more >
Memory Loss Evaluation
The following questions may help determine if a professional evaluation may be necessary: Are you becoming more forgetful?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found