Open Bug 389704 Opened 15 years ago Updated 4 years ago

Large memory leak when changing textarea.value


(Core :: DOM: Core & HTML, defect, P5)






(Reporter: yann.hamon, Unassigned)


(Keywords: testcase)


(1 file)

1.04 KB, text/html;charset=utf-8
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20061201 Firefox/ (Ubuntu-feisty)
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20061201 Firefox/ (Ubuntu-feisty)


I built a javascript "logging" in a textarea; like textarea += text, and this 3000 times. The more text there is, the more memory it uses, and the fastest the memory footprint grows. 
The exact line was:

document.getElementById("pl_dokukiwix_log").value += currentHours+":"+currentMinutes+":"+currentSeconds+" "+logstring+"\n";

This line (after being called 1000 times) caused firefox to use over 500MB of memory; deleting this line solved the memory problem.

Reproducible: Always

Steps to Reproduce:
Component: General → DOM: HTML
Product: Firefox → Core
QA Contact: general → general
Summary: Important memory leak when working with textarea → Large memory leak when changing textarea.value
Minimal testcase would be great.
Attached file testcase
I tested the latest trunk nightly under WinXP with 300 iterations, 1000 took far too long. You could also take a look at the testcase for bug 190147.

With this test, I get the following numbers for firefox.exe's VM Size as reported by Task Manager:

New start with testcase loaded: 23332K.
Press the first button, VM Size climbs to 23672K.
Press the second button, VM Size climbs from 23672K to 58328K.
Leave the browser alone for a minute, VM Size drops to 50816K.

Textarea's value.length after running this test is 15600.
OS: Linux → All
Hardware: PC → All
Component: DOM: HTML → DOM: Core & HTML
I got this problem also when I tried to use two textareas, one as a log (same as original bug reporter) and another textarea for outputting data.

I got the problem with Firefox 3.0.7, on Vista.  On this system with 3GB of RAM, Firefox crashes after using 1.8GB of memory.

I also got the problem on XP.  On this system with 2GB of RAM , Firefox starts out using 38MB and tops out at 440MB.  I even paused the logging and it did not recover any memory.

I found a workaround where I removeChild the textarea and createElement/appendChild a new textarea with same configuration.  This seems to contain the memory leak.

I do something like this to solve the problem:


var logtext = document.getElementById("texttest").value;

logtext = "" + hour + ":" + minute + ":" + second + " " + newlogtext + "\r\n" + logtext;

// delete current textarea node

// create a new text area and set its attributes same as the original text area
var textarea_element = document.createElement("textarea"); = "texttest";
textarea_element.readonly = "true";
textarea_element.rows = "20";
textarea_element.cols = "120";

textarea_element.value = logtext;

(In reply to comment #0)
Stop bothering developers with this minor problem, you are the only one, who has it
#4: If you cannot confirm the described problem, please tell us.

I tested with Minefield (latest) on Win 7.
The Memory rise was only about 4/5 MB. (I have 512 MB totally)

When setting iterations to 1000 the memory usage rose up to 52MB (from 48MB) and then did not change. After some time I closed the Firefox window, cause it took so long.
The testcase runs fast on trunk builds.
Is there anything which hints that there might be (still?) some memory leak?
excuses for comment 4, some is spamming various bugs, see bug 567347
Keywords: testcase

Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.