Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak due to uncontrolled initializations of markdown-it #605

Open
baikinkirill opened this issue Jan 20, 2025 · 0 comments
Open

Memory leak due to uncontrolled initializations of markdown-it #605

baikinkirill opened this issue Jan 20, 2025 · 0 comments

Comments

@baikinkirill
Copy link

Package version

4.41.0

Node version

20.10.0

Platform

No response

What steps will reproduce the bug?

Hi! We are using @diplodoc/transform, and our users have noticed that when rapidly switching between screens containing markdown content, the memory usage of the tab keeps increasing. We found the cause in these lines of code. In short, due to the initializations of markdown-it and its plugins for each markdown transformation, a memory leak occurs.

We made some modifications in the code within node_modules: now, the initMarkdownIt function is called only once:

function getTransformer(options = {}) {
    const { parse, compile, env } = (0, md_1.default)(options);

    return (originInput) => {
        const input = applyLiquid(originInput, options);

        try {
            return emitResult(compile(parse(input)), env);
        }
        catch (error) {
            handleError(error, options.path);
        }
    }
}

And the issue was resolved. The memory consumption stopped increasing.

What is the expected behavior?

It is expected that with each use of the transform function, markdown-it along with its plugins will not be initialized uncontrollably, thereby preventing memory clutter.

What do you see instead?

Image

Additional information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant