Closed
Bug 283564
Opened 20 years ago
Closed 20 years ago
possible memory leak with innerHTML
Categories
(Core :: DOM: HTML Parser, defect)
Tracking
()
RESOLVED
FIXED
mozilla1.8beta2
People
(Reporter: syskin2, Assigned: mrbkap)
Details
(Keywords: memory-leak)
Attachments
(3 files)
398 bytes,
text/html
|
Details | |
526 bytes,
application/xhtml+xml
|
Details | |
756 bytes,
patch
|
bzbarsky
:
review+
bzbarsky
:
superreview+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8b2) Gecko/20050224 Firefox/1.0+
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8b2) Gecko/20050224 Firefox/1.0+
Whenever JS resets the contents of innerHTML assinging an empty string to it,
and then assigning some new string, memory usage grows.
Reproducible: Always
Steps to Reproduce:
1. Open task manager to see memory usage
2. Open the attached testcase
3. Wait a bit for the script to loop, ignore possible warning about the script
looping forever. It's a small testcase so I made it run 50,000 times for
400..500mb usage.
Actual Results:
Memory meter draws a nice linear climb in mem usage.
Expected Results:
No extra memory used when the loop loops.
I found it on a real webpage, where innerhtml was used to build a menu system.
The innerHTML part was much larger there (several <img> tags on each call) so it
is easy to use 200mb memory just by using the menu for a couple of minutes.
Please note that if I didn't set innerHTML=''; on the first line, memory would
not grow.
Memory does not go down immidielty after the window/tab closes. It might go down
if you minimize the window, but even then, even invoking context menu makes
memory grow to 100mb again. In other words, firefox will never be the same until
proper restart.
Reporter | ||
Comment 1•20 years ago
|
||
loops 50k times and resets and adds innerHTML each time. memory grows.
Comment 2•20 years ago
|
||
linux: confirmed firefox trunk 2005-02-24-18Z, memory usage grew to >400M on
testcase. seamonkey 1.8a6 doesn't have the problem.
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Windows 2000 → All
Comment 3•20 years ago
|
||
not seeing the issue with a 2005-02-18 trunk seamonkey either.
Comment 4•20 years ago
|
||
I'm not seeing the memory leak with 2005-02-18 trunk Firefox build.
But I'm seeing it with 2005-02-19 trunk Firefox build.
So I guess this could be a regression from bug 263053.
Assignee | ||
Comment 5•20 years ago
|
||
Does this memory leak also occur when using createContextualFragment in XML
(i.e., using innerHTML in an XHTML document)?
Comment 6•20 years ago
|
||
No, in that case I don't think I see a memory leak.
Assignee | ||
Comment 7•20 years ago
|
||
I should read more carefully: the |.innerHTML = ''| was precisely the culprit.
When nsParser::ParseFragment() called nsParser::Parse(), the incoming string
was empty, and the aLastCall parameter was |PR_TRUE|, resulting in an immediate
return from the function. This meant that the fragment sink's DidBuildModel()
function was not called, and the parser-sink combo leaked. The XML side of this
does not have this problem, as its last call is always guarenteed to have at
least the document element's end tag in it, so DidBuildModel() will always be
called.
Now, I release the parser when we stop using it (after DidBuildContent), so the
parser no longer leaks.
Assignee: parser → mrbkap
Status: NEW → ASSIGNED
Assignee | ||
Updated•20 years ago
|
Attachment #175601 -
Flags: review?(bzbarsky)
![]() |
||
Comment 8•20 years ago
|
||
Comment on attachment 175601 [details] [diff] [review]
patch v1
r+sr=bzbarsky, but document on the fragment sink api that once you've parsed
one fragment the sink will not work unless you reset it as the sink on the
parser (which is pretty backwards, but there we are).
Attachment #175601 -
Flags: superreview+
Attachment #175601 -
Flags: review?(bzbarsky)
Attachment #175601 -
Flags: review+
Assignee | ||
Comment 9•20 years ago
|
||
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.8beta2
Reporter | ||
Comment 10•20 years ago
|
||
Confirmed fixed with the testcase - and now guess what, the menu system I was
talking about is leaking just like before ;) Expect a new bug when I create
another testcase. Heh ;-)
You need to log in
before you can comment on or make changes to this bug.
Description
•