Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Memory leak when using fromTextArea #6410

Closed

Description

@RyuDoizaki

I found a memory leak but the issue was rejected due to lack of explanation.
#6409

In the previous issue, I explained that entering characters is a condition for memory leaks. But, I found that it can be reproduced simply by setting it to {autoFocus: true}.
Just by repeating fromTextArea and toTextArea, garbage will be accumulated in the memory.
These are not deleted when you run garbage collection (press the trash can icon).

memory_leak2

<html>
    <head>
        <link rel="stylesheet" href="./codemirror-5.57.0/lib/codemirror.css">
        <script src="./codemirror-5.57.0/lib/codemirror.js"></script>
    </head>
    <body>
        <textarea id="targetTextarea" cols="30" rows="10"></textarea>
        <br><br><div id="add">add and remove 1000</div>
        <script>
            let codemirror = undefined;
            let targetTextareaEl = undefined;
            let add = undefined;

            window.onload = function(){
                targetTextareaEl = document.querySelector('#targetTextarea');
                addEl = document.querySelector('#add');
                addEl.addEventListener('click', () => {
                    for (let i = 0; i < 1000; i++) {
                        codemirror = CodeMirror.fromTextArea(targetTextareaEl, { autofocus: true });
                        codemirror.toTextArea();
                    }
                    codemirror = undefined;
                });
            }
        </script>
    </body>
</html>

I think this is a big problem for Single Page Application.

Activity

  1. marijnh commented on Sep 11, 2020

    @marijnh
    Member

    Thanks for the more detailed script, and sorry for closing so quickly before (I have wasted a lot of time on incorrect memory leak claims in the past, which has soured me a bit on the subject).

    But indeed, I can reproduce this now. The problem was indeed related to the autofocus, which caused a focus flag to be set even though the editor wasn't actually focused. That, in turn, led to the editor not firing a blur event when removed from the DOM, which caused the cursor blink interval to continue firing forever.

  2. added a commit that references this issue on Oct 31, 2020
    14d7274
  3. added a commit that references this issue on May 1, 2024
    2250b4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions